internal/lsp: add check for nil package

Fixes golang/go#31604

Change-Id: I60ec000d505c64783e5f51f62d168dc31c2fbe19
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172968
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
diff --git a/internal/lsp/source/identifier.go b/internal/lsp/source/identifier.go
index ff75e05..a76b24b 100644
--- a/internal/lsp/source/identifier.go
+++ b/internal/lsp/source/identifier.go
@@ -54,6 +54,9 @@
 func identifier(ctx context.Context, v View, f File, pos token.Pos) (*IdentifierInfo, error) {
 	fAST := f.GetAST(ctx)
 	pkg := f.GetPackage(ctx)
+	if pkg == nil {
+		return nil, fmt.Errorf("no package for %s", f.URI())
+	}
 	if pkg.IsIllTyped() {
 		return nil, fmt.Errorf("package for %s is ill typed", f.URI())
 	}