gopls/internal/lsp/source: add the "symbolScope" option
Add a new "symbolScope" option that controls whether matches are
restricted to workspace packages only. This is the new default behavior,
though the old behavior can be enabled by setting "symbolScope": "all".
Fixes golang/go#37236
Change-Id: Ic614b57005488e61ea0c018a68076785e667db16
Reviewed-on: https://go-review.googlesource.com/c/tools/+/490935
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
diff --git a/gopls/internal/lsp/cache/snapshot.go b/gopls/internal/lsp/cache/snapshot.go
index 62a84c5..6bd4be8 100644
--- a/gopls/internal/lsp/cache/snapshot.go
+++ b/gopls/internal/lsp/cache/snapshot.go
@@ -1113,18 +1113,26 @@
// a loaded package. It awaits snapshot loading.
//
// TODO(rfindley): move this to the top of cache/symbols.go
-func (s *snapshot) Symbols(ctx context.Context) (map[span.URI][]source.Symbol, error) {
+func (s *snapshot) Symbols(ctx context.Context, workspaceOnly bool) (map[span.URI][]source.Symbol, error) {
if err := s.awaitLoaded(ctx); err != nil {
return nil, err
}
- // Build symbols for all loaded Go files.
- s.mu.Lock()
- meta := s.meta
- s.mu.Unlock()
+ var (
+ meta []*source.Metadata
+ err error
+ )
+ if workspaceOnly {
+ meta, err = s.WorkspaceMetadata(ctx)
+ } else {
+ meta, err = s.AllMetadata(ctx)
+ }
+ if err != nil {
+ return nil, fmt.Errorf("loading metadata: %v", err)
+ }
goFiles := make(map[span.URI]struct{})
- for _, m := range meta.metadata {
+ for _, m := range meta {
for _, uri := range m.GoFiles {
goFiles[uri] = struct{}{}
}