From d55b9fb8ef72d82490e38e4b1263c176592987ae Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Wed, 13 Mar 2019 14:25:56 -0400 Subject: [PATCH] internal/lsp: stop providing insertText for completion items InsertText is deprecated, and it seems that providing both InsertText and TextEdits causes unexpected behavior from VSCode. Avoid this by providing only TextEdits. Fixes golang/go#30796 Change-Id: Ieb5ad2fecd6f7083a4c1bc402634893c7e6ff49f Reviewed-on: https://go-review.googlesource.com/c/tools/+/167457 Reviewed-by: Ian Cottrell Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot --- internal/lsp/completion.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/lsp/completion.go b/internal/lsp/completion.go index b9f4e209..50f82923 100644 --- a/internal/lsp/completion.go +++ b/internal/lsp/completion.go @@ -28,15 +28,17 @@ func toProtocolCompletionItems(candidates []source.CompletionItem, prefix string if !strings.HasPrefix(candidate.Label, prefix) { continue } + // InsertText is deprecated in favor of TextEdits. + // TODO(rstambler): Remove this logic when we are confident that we no + // longer need to support it. insertText, triggerSignatureHelp := labelToProtocolSnippets(candidate.Label, candidate.Kind, insertTextFormat, signatureHelpEnabled) if strings.HasPrefix(insertText, prefix) { insertText = insertText[len(prefix):] } item := protocol.CompletionItem{ - Label: candidate.Label, - Detail: candidate.Detail, - Kind: toProtocolCompletionItemKind(candidate.Kind), - InsertTextFormat: protocol.PlainTextTextFormat, + Label: candidate.Label, + Detail: candidate.Detail, + Kind: toProtocolCompletionItemKind(candidate.Kind), TextEdit: &protocol.TextEdit{ NewText: insertText, Range: protocol.Range{ @@ -44,8 +46,6 @@ func toProtocolCompletionItems(candidates []source.CompletionItem, prefix string End: pos, }, }, - // InsertText is deprecated in favor of TextEdit. - InsertText: insertText, // This is a hack so that the client sorts completion results in the order // according to their score. This can be removed upon the resolution of // https://github.com/Microsoft/language-server-protocol/issues/348.