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 <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Trust: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Matheus Alcantara 2020-12-29 21:42:38 +00:00 committed by Rebecca Stambler
parent 929a8494cf
commit b8413747bb
1 changed files with 4 additions and 0 deletions

View File

@ -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