Skip to content

Commit b841374

Browse files
mattheusvstamblerre
authored andcommitted
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: e7b189a GitHub-Pull-Request: #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>
1 parent 929a849 commit b841374

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

internal/lsp/source/completion/completion.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,10 @@ func (c *completer) emptySwitchStmt() bool {
733733
// (i.e. "golang.org/x/"). The user is meant to accept completion suggestions
734734
// until they reach a complete import path.
735735
func (c *completer) populateImportCompletions(ctx context.Context, searchImport *ast.ImportSpec) error {
736+
if !strings.HasPrefix(searchImport.Path.Value, `"`) {
737+
return nil
738+
}
739+
736740
// deepSearch is not valuable for import completions.
737741
c.deepState.enabled = false
738742

0 commit comments

Comments
 (0)