From b8413747bbd4168dd39cefbee0bddf23d831d79e Mon Sep 17 00:00:00 2001 From: Matheus Alcantara Date: Tue, 29 Dec 2020 21:42:38 +0000 Subject: [PATCH] internal/lsp: fix autocomplete appends on imports Autocompleting a import without quotes appends to the completion, producing this result: `import math "math/"`. This commit changes to skip completions when typing a import without quotes, because the users can be typing the alias of the import. Fixes: golang/go#42748 Change-Id: I7050989f1f90a6720c17f71f338e50fad1f01456 GitHub-Last-Rev: e7b189a04acd8e501d6d7ac944d25de19156d0da GitHub-Pull-Request: golang/tools#263 Reviewed-on: https://go-review.googlesource.com/c/tools/+/280652 Reviewed-by: Rebecca Stambler Run-TryBot: Rebecca Stambler gopls-CI: kokoro TryBot-Result: Go Bot Trust: Hyang-Ah Hana Kim Trust: Rebecca Stambler --- internal/lsp/source/completion/completion.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/lsp/source/completion/completion.go b/internal/lsp/source/completion/completion.go index 9e592d6788..51f85d1408 100644 --- a/internal/lsp/source/completion/completion.go +++ b/internal/lsp/source/completion/completion.go @@ -733,6 +733,10 @@ func (c *completer) emptySwitchStmt() bool { // (i.e. "golang.org/x/"). The user is meant to accept completion suggestions // until they reach a complete import path. func (c *completer) populateImportCompletions(ctx context.Context, searchImport *ast.ImportSpec) error { + if !strings.HasPrefix(searchImport.Path.Value, `"`) { + return nil + } + // deepSearch is not valuable for import completions. c.deepState.enabled = false