From 95bc2bdf7e31d255ef5ac04e85be0e11883c7cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20L=2E=20Hansen?= Date: Sun, 5 Jul 2020 14:03:18 +0200 Subject: [PATCH] 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 --- internal/lsp/source/completion.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/lsp/source/completion.go b/internal/lsp/source/completion.go index 2c7a3afc68..f3b8802189 100644 --- a/internal/lsp/source/completion.go +++ b/internal/lsp/source/completion.go @@ -755,6 +755,9 @@ func (c *completer) populateCommentCompletions(ctx context.Context, comment *ast } 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