internal/lsp/cache: simplify importsState modfile hashing logic
While checking for changes to go.mod files in the importsState, there is
no reason for special handling based on workspace mode: we can simply
hash all active modfiles. This moves us towards an improved API for the
workspace: it should simply be responsible for tracking active modfiles.
This also incidentally avoids the panic reported in golang/go#55837.
Fixes golang/go#55837
Change-Id: I8cb345d1689be12382683186afe3f9addb19d467
Reviewed-on: https://go-review.googlesource.com/c/tools/+/447956
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/gopls/internal/lsp/cache/snapshot.go b/gopls/internal/lsp/cache/snapshot.go
index eed7dfc..b05f401 100644
--- a/gopls/internal/lsp/cache/snapshot.go
+++ b/gopls/internal/lsp/cache/snapshot.go
@@ -250,7 +250,7 @@
func (s *snapshot) ModFiles() []span.URI {
var uris []span.URI
- for modURI := range s.workspace.getActiveModFiles() {
+ for modURI := range s.workspace.ActiveModFiles() {
uris = append(uris, modURI)
}
return uris
@@ -281,7 +281,7 @@
}
// Check if the user is working within a module or if we have found
// multiple modules in the workspace.
- if len(s.workspace.getActiveModFiles()) > 0 {
+ if len(s.workspace.ActiveModFiles()) > 0 {
return true
}
// The user may have a multiple directories in their GOPATH.
@@ -308,7 +308,7 @@
// If the view is not in a module and contains no modules, but still has a
// valid workspace configuration, do not create the workspace module.
// It could be using GOPATH or a different build system entirely.
- if len(s.workspace.getActiveModFiles()) == 0 && validBuildConfiguration {
+ if len(s.workspace.ActiveModFiles()) == 0 && validBuildConfiguration {
return mode
}
mode |= moduleMode
@@ -480,7 +480,7 @@
if mode == source.LoadWorkspace {
switch s.workspace.moduleSource {
case legacyWorkspace:
- for m := range s.workspace.getActiveModFiles() { // range to access the only element
+ for m := range s.workspace.ActiveModFiles() { // range to access the only element
modURI = m
}
case goWorkWorkspace: