1
0
mirror of https://github.com/golang/go synced 2024-11-18 16:04:44 -07:00

cmd/lsp: skip completion in string literals

This CL ensures that a "." inside a string literal will return an empty
completion list.

Fixes golang/go#30477

Change-Id: I1442d0acab4c12a829047805f745c4729d69c208
Reviewed-on: https://go-review.googlesource.com/c/tools/+/167857
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Marwan Sulaiman 2019-03-15 12:10:31 -04:00 committed by Rebecca Stambler
parent 8110780cfa
commit f59e586bb3
3 changed files with 12 additions and 3 deletions

View File

@ -36,7 +36,7 @@ func testLSP(t *testing.T, exporter packagestest.Exporter) {
// We hardcode the expected number of test cases to ensure that all tests
// are being executed. If a test is added, this number must be changed.
const expectedCompletionsCount = 63
const expectedCompletionsCount = 64
const expectedDiagnosticsCount = 16
const expectedFormatCount = 4
const expectedDefinitionsCount = 16

View File

@ -69,12 +69,16 @@ func Completion(ctx context.Context, f File, pos token.Pos) (items []CompletionI
}
}
// Skip completion inside comment blocks.
switch path[0].(type) {
// Skip completion inside comment blocks or string literals.
switch lit := path[0].(type) {
case *ast.File, *ast.BlockStmt:
if inComment(pos, file.Comments) {
return items, prefix, nil
}
case *ast.BasicLit:
if lit.Kind == token.STRING {
return items, prefix, nil
}
}
// Save certain facts about the query position, including the expected type

View File

@ -0,0 +1,5 @@
package stringlit
func _() {
_ := "hello." //@complete(".")
}