internal/lsp/cache: fix panic in GOPATH mode
We can't assume that we're in module mode when we rebuild the imports
cache. (This is a long standing bug, but I suspect it was made more
common by my recent CL that refactored this code.)
Fixes golang/go#43544.
Change-Id: Ie35c43e6b6e496bd2fbf49cf9bf06c28cf1dab80
Reviewed-on: https://go-review.googlesource.com/c/tools/+/282113
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
diff --git a/internal/lsp/cache/imports.go b/internal/lsp/cache/imports.go
index 7896d11..ed9919f 100644
--- a/internal/lsp/cache/imports.go
+++ b/internal/lsp/cache/imports.go
@@ -78,7 +78,9 @@
// unnecessary work and potentially mess up the go.mod file.
if s.cleanupProcessEnv != nil {
if resolver, err := s.processEnv.GetResolver(); err == nil {
- resolver.(*imports.ModuleResolver).ClearForNewMod()
+ if modResolver, ok := resolver.(*imports.ModuleResolver); ok {
+ modResolver.ClearForNewMod()
+ }
}
s.cleanupProcessEnv()
}