From eac381796e91db0acd689726cce5b78086509607 Mon Sep 17 00:00:00 2001 From: Muir Manders Date: Sun, 12 Jan 2020 19:27:12 -0800 Subject: [PATCH] internal/lsp: fix completion ordering workaround Our loop to make all candidates use the same "filterText" wasn't including the final candidate. This was causing strange ordering of candidates in VSCode when the "worst" candidate happened to match the prefix exactly (causing VSCode to reorder it to the top). Fixes golang/go#36519. Change-Id: Ie2119ca94d13f337edd241fbde862706bdeee191 Reviewed-on: https://go-review.googlesource.com/c/tools/+/214184 Run-TryBot: Muir Manders TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/lsp/completion.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/lsp/completion.go b/internal/lsp/completion.go index 90bcba9c73..7061ff9548 100644 --- a/internal/lsp/completion.go +++ b/internal/lsp/completion.go @@ -66,9 +66,9 @@ func (s *Server) completion(ctx context.Context, params *protocol.CompletionPara items := toProtocolCompletionItems(candidates, rng, options) - if incompleteResults && len(items) > 1 { - for i := range items[1:] { - // Give all the candidaites the same filterText to trick VSCode + if incompleteResults { + for i := 1; i < len(items); i++ { + // Give all the candidates 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"