internal/lsp/source: fix duplicates in workspaceSymbols
The logic to de-dupe workspace symbols was broken in two ways:
- The 'seen' map of files already processed was never written.
- The key to 'seen' was *ast.File, which doesn't work if we parse
twice.
Fix this by de-duping instead on span.URI.
Change-Id: Iedadfac17a0a993570ff4f8301a97815477f1c2c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254117
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
(cherry picked from commit 571a207697e7c073370297b1f73b9fbd7682a851)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254217
diff --git a/internal/lsp/source/workspace_symbol.go b/internal/lsp/source/workspace_symbol.go
index 62f6adf..1b6fd99 100644
--- a/internal/lsp/source/workspace_symbol.go
+++ b/internal/lsp/source/workspace_symbol.go
@@ -16,6 +16,7 @@
"golang.org/x/tools/internal/event"
"golang.org/x/tools/internal/lsp/fuzzy"
"golang.org/x/tools/internal/lsp/protocol"
+ "golang.org/x/tools/internal/span"
)
// maxSymbols defines the maximum number of symbol results that should ever be
@@ -278,13 +279,14 @@
}
// Make sure we only walk files once (we might see them more than once due to
// build constraints).
- seen := make(map[*ast.File]bool)
+ seen := make(map[span.URI]bool)
for _, pv := range toWalk {
sc.current = pv
for _, pgf := range pv.pkg.CompiledGoFiles() {
- if seen[pgf.File] {
+ if seen[pgf.URI] {
continue
}
+ seen[pgf.URI] = true
sc.curFile = pgf
sc.walkFilesDecls(pgf.File.Decls)
}