internal/lsp/source: handle nil pointer in comment completions
c.pkg.GetTypeInfo().ObjectOf(node.Name) will sometimes return nil.
Check for that and a few other things that c.found also checks for.
Fixes golang/go#40043
Change-Id: I4a2b40adbbd740323e10b3460f025b29cff74130
Reviewed-on: https://go-review.googlesource.com/c/tools/+/241019
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/internal/lsp/source/completion.go b/internal/lsp/source/completion.go
index 2c7a3af..f3b8802 100644
--- a/internal/lsp/source/completion.go
+++ b/internal/lsp/source/completion.go
@@ -755,6 +755,9 @@
}
obj := c.pkg.GetTypesInfo().ObjectOf(node.Name)
+ if obj == nil || obj.Pkg() != nil && obj.Pkg() != c.pkg.GetTypes() {
+ continue
+ }
// We don't want expandFuncCall inside comments. We add this directly to the
// completions list because using c.found sets expandFuncCall to true by default