diff --git a/internal/lsp/lsp_test.go b/internal/lsp/lsp_test.go index 00187cb4bc..eec3cb86ff 100644 --- a/internal/lsp/lsp_test.go +++ b/internal/lsp/lsp_test.go @@ -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 diff --git a/internal/lsp/source/completion.go b/internal/lsp/source/completion.go index 86c1b6d646..81702ea092 100644 --- a/internal/lsp/source/completion.go +++ b/internal/lsp/source/completion.go @@ -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 diff --git a/internal/lsp/testdata/stringlit/stringlit.go.in b/internal/lsp/testdata/stringlit/stringlit.go.in new file mode 100644 index 0000000000..2558eb5790 --- /dev/null +++ b/internal/lsp/testdata/stringlit/stringlit.go.in @@ -0,0 +1,5 @@ +package stringlit + +func _() { + _ := "hello." //@complete(".") +}