internal/lsp/source: avoid panic in HoverIdentifier

Fixes golang/go#52211

Change-Id: I2ab5dbba4bb06092a234269d1ee65493f60fc6fc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/399622
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/internal/lsp/source/hover.go b/internal/lsp/source/hover.go
index 34c80ab..07b6aa4 100644
--- a/internal/lsp/source/hover.go
+++ b/internal/lsp/source/hover.go
@@ -405,6 +405,12 @@
 		return "", "", ""
 	}
 
+	// golang/go#52211: somehow we get here with a nil obj.Pkg
+	// TODO: allow using debug.Bug here, to catch this bug.
+	if obj.Pkg() == nil {
+		return "", "", ""
+	}
+
 	importPath = obj.Pkg().Path()
 	if recv != nil {
 		anchor = fmt.Sprintf("%s.%s", recv.Name(), obj.Name())