internal/lsp: fix panics in loading, add more logging

Fixes golang/go#32929

Change-Id: I15e258fe03ef07dbb4ece79f52cb0d0353c8b0b1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185994
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/cache/load.go b/internal/lsp/cache/load.go
index f0e4bbb..d0c2b1d 100644
--- a/internal/lsp/cache/load.go
+++ b/internal/lsp/cache/load.go
@@ -100,7 +100,10 @@
 	}
 	// Track missing imports as we look at the package's errors.
 	missingImports := make(map[packagePath]struct{})
+
+	xlog.Debugf(ctx, "packages.Load: found %v packages", len(pkgs))
 	for _, pkg := range pkgs {
+		xlog.Debugf(ctx, "packages.Load: package %s with files %v", pkg.PkgPath, pkg.CompiledGoFiles)
 		// If the package comes back with errors from `go list`,
 		// don't bother type-checking it.
 		if len(pkg.Errors) > 0 {
@@ -226,10 +229,12 @@
 		f, err := v.getFile(ctx, span.FileURI(filename))
 		if err != nil {
 			xlog.Errorf(ctx, "no file %s: %v", filename, err)
+			continue
 		}
 		gof, ok := f.(*goFile)
 		if !ok {
 			xlog.Errorf(ctx, "not a Go file: %s", f.URI())
+			continue
 		}
 		if gof.meta == nil {
 			gof.meta = make(map[packageID]*metadata)