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

Support TextEdit in completion responses #4073

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
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
19 changes: 13 additions & 6 deletions src/features/completionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,26 @@ export default class OmnisharpCompletionProvider extends AbstractProvider implem
}

private _convertToVscodeCompletionItem(omnisharpCompletion: protocol.OmnisharpCompletionItem): CompletionItem {
let docs: MarkdownString | undefined = omnisharpCompletion.Documentation ? new MarkdownString(omnisharpCompletion.Documentation, false) : undefined;
const docs: MarkdownString | undefined = omnisharpCompletion.Documentation ? new MarkdownString(omnisharpCompletion.Documentation, false) : undefined;

const mapTextEdit = function (edit: protocol.LinePositionSpanTextChange): TextEdit {
const mapRange = function (edit: protocol.LinePositionSpanTextChange): Range {
const newStart = new Position(edit.StartLine - 1, edit.StartColumn - 1);
const newEnd = new Position(edit.EndLine - 1, edit.EndColumn - 1);
const newRange = new Range(newStart, newEnd);
return new TextEdit(newRange, edit.NewText);
return new Range(newStart, newEnd);
};

const mapTextEdit = function (edit: protocol.LinePositionSpanTextChange): TextEdit {
return new TextEdit(mapRange(edit), edit.NewText);
};

const additionalTextEdits = omnisharpCompletion.AdditionalTextEdits?.map(mapTextEdit);

const newText = omnisharpCompletion.TextEdit?.NewText ?? omnisharpCompletion.InsertText;
const insertText = omnisharpCompletion.InsertTextFormat === InsertTextFormat.Snippet
? new SnippetString(omnisharpCompletion.InsertText)
: omnisharpCompletion.InsertText;
? new SnippetString(newText)
: newText;

const insertRange = omnisharpCompletion.TextEdit ? mapRange(omnisharpCompletion.TextEdit) : undefined;

return {
label: omnisharpCompletion.Label,
Expand All @@ -84,6 +90,7 @@ export default class OmnisharpCompletionProvider extends AbstractProvider implem
preselect: omnisharpCompletion.Preselect,
filterText: omnisharpCompletion.FilterText,
insertText: insertText,
range: insertRange,
tags: omnisharpCompletion.Tags,
sortText: omnisharpCompletion.SortText,
additionalTextEdits: additionalTextEdits,
Expand Down
1 change: 1 addition & 0 deletions src/omnisharp/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ export interface OmnisharpCompletionItem {
FilterText?: string;
InsertText?: string;
InsertTextFormat?: InsertTextFormat;
TextEdit?: LinePositionSpanTextChange;
CommitCharacters?: string[];
AdditionalTextEdits?: LinePositionSpanTextChange[];
Data: any;
Expand Down