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>
diff --git a/internal/lsp/lsp_test.go b/internal/lsp/lsp_test.go
index 00187cb..eec3cb8 100644
--- a/internal/lsp/lsp_test.go
+++ b/internal/lsp/lsp_test.go
@@ -36,7 +36,7 @@
 
 	// 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 86c1b6d..81702ea 100644
--- a/internal/lsp/source/completion.go
+++ b/internal/lsp/source/completion.go
@@ -69,12 +69,16 @@
 		}
 	}
 
-	// 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 0000000..2558eb5
--- /dev/null
+++ b/internal/lsp/testdata/stringlit/stringlit.go.in
@@ -0,0 +1,5 @@
+package stringlit
+
+func _() {
+	_ := "hello." //@complete(".")
+}