internal/lsp: don't search for workspace modules by default
This may be expensive, and we don't want to do it if the results will
be unused.
Updates golang/go#41558
Change-Id: I0c01a80f4fc459e1cc189934ad23ab443e5ea2a5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/257137
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/internal/lsp/cache/session.go b/internal/lsp/cache/session.go
index 6e31395..b8764ef 100644
--- a/internal/lsp/cache/session.go
+++ b/internal/lsp/cache/session.go
@@ -166,10 +166,14 @@
return nil, nil, func() {}, err
}
- // Find all of the modules in the workspace.
- modules, err := findWorkspaceModules(ctx, ws.rootURI, options)
- if err != nil {
- return nil, nil, func() {}, err
+ // If workspace module mode is enabled, find all of the modules in the
+ // workspace.
+ var modules map[span.URI]*moduleRoot
+ if options.ExperimentalWorkspaceModule {
+ modules, err = findWorkspaceModules(ctx, ws.rootURI, options)
+ if err != nil {
+ return nil, nil, func() {}, err
+ }
}
// Now that we have set all required fields,