Skip to content

Commit f970c5c

Browse files
committed
Fix indentation for snippet strings within code actions.
- Language server (JDT-LS) handles appropriate indentation so indicate to client that whitespace is to be preserved Signed-off-by: Roland Grunberg <[email protected]>
1 parent 4eeaf73 commit f970c5c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/extension.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as fse from 'fs-extra';
66
import * as os from 'os';
77
import * as path from 'path';
88
import * as semver from 'semver';
9-
import { CodeActionContext, commands, CompletionItem, ConfigurationTarget, Diagnostic, env, EventEmitter, ExtensionContext, extensions, IndentAction, InputBoxOptions, languages, Location, MarkdownString, QuickPickItemKind, Range, RelativePattern, SnippetString, SnippetTextEdit, TextDocument, TextEditorRevealType, UIKind, Uri, ViewColumn, window, workspace, WorkspaceConfiguration, WorkspaceEdit } from 'vscode';
9+
import { CodeActionContext, commands, CompletionItem, ConfigurationTarget, Diagnostic, env, EventEmitter, ExtensionContext, extensions, IndentAction, InputBoxOptions, languages, Location, MarkdownString, QuickPickItemKind, Range, RelativePattern, SnippetString, SnippetTextEdit, TextDocument, TextEditorRevealType, UIKind, Uri, version, ViewColumn, window, workspace, WorkspaceConfiguration, WorkspaceEdit } from 'vscode';
1010
import { CancellationToken, CodeActionParams, CodeActionRequest, CodeActionResolveRequest, Command, CompletionRequest, DidChangeConfigurationNotification, ExecuteCommandParams, ExecuteCommandRequest, LanguageClientOptions, RevealOutputChannelOn } from 'vscode-languageclient';
1111
import { LanguageClient } from 'vscode-languageclient/node';
1212
import { apiManager } from './apiManager';
@@ -318,7 +318,11 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
318318
for (const edit of docChange.edits) {
319319
if ("snippet" in edit) {
320320
documentUris.push(Uri.parse(docChange.textDocument.uri).toString());
321-
snippetEdits.push(new SnippetTextEdit(client.protocol2CodeConverter.asRange((edit as any).range), new SnippetString((edit as any).snippet.value)));
321+
const snippet = new SnippetTextEdit(client.protocol2CodeConverter.asRange((edit as any).range), new SnippetString((edit as any).snippet.value));
322+
if (semver.gte(version, '1.98.0')) {
323+
snippet["keepWhitespace"] = true;
324+
}
325+
snippetEdits.push(snippet);
322326
}
323327
}
324328
}

0 commit comments

Comments
 (0)