Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing snippets in new LSP completion #7274

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/razor/src/completion/completionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
CompletionParams,
CompletionTriggerKind,
InsertReplaceEdit,
InsertTextFormat,
InsertTextMode,
MarkupContent,
Position,
Expand Down Expand Up @@ -344,6 +345,7 @@ export class CompletionHandler {
documentation: CompletionHandler.toMarkupContent(completionItem.documentation),
filterText: completionItem.filterText,
insertText: CompletionHandler.toLspInsertText(completionItem.insertText),
insertTextFormat: CompletionHandler.toLspInsertTextFormat(completionItem.insertText),
insertTextMode: CompletionHandler.toInsertTextMode(completionItem.keepWhitespace),
kind: completionItem.kind ? completionItem.kind + 1 : completionItem.kind, // VSCode and LSP are off by one
label: CompletionHandler.toLspCompletionItemLabel(completionItem.label),
Expand Down Expand Up @@ -390,6 +392,19 @@ export class CompletionHandler {
return snippetString?.value ?? <string | undefined>insertText;
}

private static toLspInsertTextFormat(insertText?: string | vscode.SnippetString): InsertTextFormat {
return insertText instanceof vscode.SnippetString ? InsertTextFormat.Snippet : InsertTextFormat.PlainText;
}

private static toInsertTextMode(keepWhitespace?: boolean): InsertTextMode | undefined {
if (keepWhitespace === undefined) {
return undefined;
}

const insertTextMode: InsertTextMode = keepWhitespace ? InsertTextMode.asIs : InsertTextMode.adjustIndentation;
return insertTextMode;
}

private static toLspTextEdit(
newText?: string,
range?: vscode.Range | { inserting: vscode.Range; replacing: vscode.Range }
Expand Down Expand Up @@ -448,13 +463,4 @@ export class CompletionHandler {

return lspPosition;
}

private static toInsertTextMode(keepWhitespace?: boolean): InsertTextMode | undefined {
if (keepWhitespace === undefined) {
return undefined;
}

const insertTextMode: InsertTextMode = keepWhitespace ? InsertTextMode.asIs : InsertTextMode.adjustIndentation;
return insertTextMode;
}
}
Loading