internal/lsp: handle nil pointer exceptions in check for Go files

Fixes golang/go#42240

Change-Id: I48382613c9eb9d021a9e1dc9ca6ab6b4b1dfcf8f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/265763
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
(cherry picked from commit 8cd080b735b3b2bd82462845c2987d44a412ada9)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/265977
diff --git a/internal/lsp/diagnostics.go b/internal/lsp/diagnostics.go
index cd0f408..d0dcb27 100644
--- a/internal/lsp/diagnostics.go
+++ b/internal/lsp/diagnostics.go
@@ -460,6 +460,9 @@
 	// If the folder has no Go code in it, we shouldn't spam the user with a warning.
 	var hasGo bool
 	_ = filepath.Walk(snapshot.View().Folder().Filename(), func(path string, info os.FileInfo, err error) error {
+		if err != nil {
+			return err
+		}
 		if !strings.HasSuffix(info.Name(), ".go") {
 			return nil
 		}