internal/lsp: never reload command-line-arguments directly
I'm not sure if this is entirely the correct approach, but at the very
least we should never pass "command-line-arguments" to packages.Load. We
still need to cache packages with the path "command-line-arguments" to
avoid an excessive number of calls to packages.Load.
Updates golang/go#37978
Change-Id: I1b5263a3dab95aacd797f03f742069fd0c53619c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/225117
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
diff --git a/internal/lsp/cache/load.go b/internal/lsp/cache/load.go
index a778c88..a95913f 100644
--- a/internal/lsp/cache/load.go
+++ b/internal/lsp/cache/load.go
@@ -43,6 +43,9 @@
for _, scope := range scopes {
switch scope := scope.(type) {
case packagePath:
+ if scope == "command-line-arguments" {
+ panic("attempted to load command-line-arguments")
+ }
// The only time we pass package paths is when we're doing a
// partial workspace load. In those cases, the paths came back from
// go list and should already be GOPATH-vendorized when appropriate.
diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go
index 2a0dbb2..95c6248 100644
--- a/internal/lsp/cache/snapshot.go
+++ b/internal/lsp/cache/snapshot.go
@@ -547,6 +547,10 @@
s.mu.Lock()
var pkgPaths []interface{}
for id, pkgPath := range s.workspacePackages {
+ // Don't try to reload "command-line-arguments" directly.
+ if pkgPath == "command-line-arguments" {
+ continue
+ }
if s.metadata[id] == nil {
pkgPaths = append(pkgPaths, pkgPath)
}