From 035a8167be0b8c5b9a6ecde6d17b0306a9d7ff6a Mon Sep 17 00:00:00 2001 From: Muir Manders Date: Fri, 22 Nov 2019 09:12:47 -0800 Subject: [PATCH] internal/lsp: improve completion ordering workaround Instead of making all completion candidates look like perfect matches to VSCode, we now make all candidates match exactly like the first candidate. This still causes VSCode to maintain the ordering from gopls, but it fixes the absolute match score of gopls's top candidates. This fixes interplay with other sources of VSCode completions, such as user defined snippets. Fixes golang/go#35782. Change-Id: Ie7e489b76a02fb1353b63fa3c6fa42afee2e1441 Reviewed-on: https://go-review.googlesource.com/c/tools/+/208439 Reviewed-by: Rebecca Stambler Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot --- internal/lsp/completion.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/lsp/completion.go b/internal/lsp/completion.go index 9d1fb72915..cc6aa87726 100644 --- a/internal/lsp/completion.go +++ b/internal/lsp/completion.go @@ -54,16 +54,16 @@ func (s *Server) completion(ctx context.Context, params *protocol.CompletionPara items := toProtocolCompletionItems(candidates, rng, options) - if incompleteResults { - prefix := surrounding.Prefix() - for i := range items { - // We send the prefix as the filterText to trick VSCode into not - // reordering our candidates. All the candidates will appear to - // be a perfect match, so VSCode's fuzzy matching/ranking just - // maintains the natural "sortText" ordering. We can only do - // this in tandem with "incompleteResults" since otherwise - // client side filtering is important. - items[i].FilterText = prefix + if incompleteResults && len(items) > 1 { + for i := range items[1:] { + // Give all the candidaites the same filterText to trick VSCode + // into not reordering our candidates. All the candidates will + // appear to be equally good matches, so VSCode's fuzzy + // matching/ranking just maintains the natural "sortText" + // ordering. We can only do this in tandem with + // "incompleteResults" since otherwise client side filtering is + // important. + items[i].FilterText = items[0].FilterText } }