Skip to content

Commit 9fc00b0

Browse files
committed
internal/lsp: fix panic in builtin completions
Fixes #38091 Change-Id: I88ac6d3413de3dd9d235e2f2fca9b4a3f7127e0a Reviewed-on: https://go-review.googlesource.com/c/tools/+/227026 Run-TryBot: Rebecca Stambler <[email protected]> Reviewed-by: Rohan Challa <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 0a46fa3 commit 9fc00b0

File tree

4 files changed

+10
-1
lines changed

4 files changed

+10
-1
lines changed

internal/lsp/source/completion_builtin.go

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ func (c *completer) builtinArgType(obj types.Object, call *ast.CallExpr, parentI
5959

6060
switch obj.Name() {
6161
case "append":
62+
if parentInf.objType == nil {
63+
break
64+
}
6265
inf.objType = parentInf.objType
6366

6467
// Check if we are completing the variadic append() param.

internal/lsp/testdata/lsp/primarymod/append/append.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ func _() {
1717
// Don't add "..." to append() argument.
1818
bar(append()) //@snippet("))", appendStrings, "aStrings", "aStrings")
1919
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package append
2+
3+
func _() {
4+
_ = append(a, struct) //@complete(")")
5+
}

internal/lsp/testdata/lsp/summary.txt.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- summary --
22
CodeLensCount = 2
3-
CompletionsCount = 237
3+
CompletionsCount = 238
44
CompletionSnippetCount = 75
55
UnimportedCompletionsCount = 11
66
DeepCompletionsCount = 5

0 commit comments

Comments
 (0)