internal/lsp: ensure that an AST cannot be nil without an error

Fixes golang/go#34366

Change-Id: I2f5269cd0b270aef5accc69adeced8be4523cb65
Reviewed-on: https://go-review.googlesource.com/c/tools/+/196142
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/parse.go b/internal/lsp/cache/parse.go
index b426a2e..537460a 100644
--- a/internal/lsp/cache/parse.go
+++ b/internal/lsp/cache/parse.go
@@ -130,14 +130,19 @@
 			log.Error(ctx, "failed to fix AST", err)
 		}
 	}
-	// If the file is nil only due to parse errors,
-	// the parse errors are the actual errors.
+
 	if file == nil {
-		return nil, nil, parseError, parseError
+		// If the file is nil only due to parse errors,
+		// the parse errors are the actual errors.
+		err := parseError
+		if err == nil {
+			err = errors.Errorf("no AST for %s", fh.Identity().URI)
+		}
+		return nil, nil, parseError, err
 	}
 	tok := c.FileSet().File(file.Pos())
 	if tok == nil {
-		return nil, nil, parseError, err
+		return nil, nil, parseError, errors.Errorf("no token.File for %s", fh.Identity().URI)
 	}
 	uri := fh.Identity().URI
 	content, _, err := fh.Read(ctx)