internal/lsp/cache: populate URI on files with errors
FileHandles with stat errors didn't have their URIs populated. It's
probably reasonable to expect URI and Kind to work on them.
Change-Id: Ic328b262803f93b5042da89a973859c598fa5beb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/256359
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/internal/lsp/cache/cache.go b/internal/lsp/cache/cache.go
index 5e54c8b..c2b4fe5 100644
--- a/internal/lsp/cache/cache.go
+++ b/internal/lsp/cache/cache.go
@@ -66,7 +66,10 @@
func (c *Cache) getFile(ctx context.Context, uri span.URI) (*fileHandle, error) {
fi, statErr := os.Stat(uri.Filename())
if statErr != nil {
- return &fileHandle{err: statErr}, nil
+ return &fileHandle{
+ err: statErr,
+ uri: uri,
+ }, nil
}
c.fileMu.Lock()
diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go
index 3d5db7a..8be2110 100644
--- a/internal/lsp/cache/snapshot.go
+++ b/internal/lsp/cache/snapshot.go
@@ -973,11 +973,9 @@
delete(result.modWhyHandles, k)
}
}
- currentExists := currentFH.URI() != ""
- if currentExists {
- if _, err := currentFH.Read(); os.IsNotExist(err) {
- currentExists = false
- }
+ currentExists := true
+ if _, err := currentFH.Read(); os.IsNotExist(err) {
+ currentExists = false
}
// If the file invalidation is for a go.mod. originalFH is nil if the
// file is newly created.