mirror of
https://github.com/golang/go
synced 2024-11-18 16:14:46 -07:00
internal/lsp/source: limit WorkspaceSymbols results
Searching with an empty string shouldn't return every symbol in the workspace -- nobody wants that. Limit to 100 results to avoid breaking editors. (VS Code locks up for like 30 seconds on my workspace.) Change-Id: I1e0be476e8eeaef9e69767bfa04a89d40bd3a6e5 Reviewed-on: https://go-review.googlesource.com/c/tools/+/220939 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
7c03e3340d
commit
c099ead939
@ -17,12 +17,15 @@ import (
|
||||
"golang.org/x/tools/internal/telemetry/trace"
|
||||
)
|
||||
|
||||
const maxSymbols = 100
|
||||
|
||||
func WorkspaceSymbols(ctx context.Context, views []View, query string) ([]protocol.SymbolInformation, error) {
|
||||
ctx, done := trace.StartSpan(ctx, "source.WorkspaceSymbols")
|
||||
defer done()
|
||||
|
||||
seen := make(map[string]struct{})
|
||||
var symbols []protocol.SymbolInformation
|
||||
outer:
|
||||
for _, view := range views {
|
||||
knownPkgs, err := view.Snapshot().KnownPackages(ctx)
|
||||
if err != nil {
|
||||
@ -57,6 +60,9 @@ func WorkspaceSymbols(ctx context.Context, views []View, query string) ([]protoc
|
||||
Range: rng,
|
||||
},
|
||||
})
|
||||
if len(symbols) > maxSymbols {
|
||||
break outer
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
package workspacesymbol
|
||||
|
||||
/*@
|
||||
workspacesymbol("",
|
||||
symbolsx,
|
||||
y,
|
||||
Number,
|
||||
Alias,
|
||||
NumberAlias,
|
||||
Boolean,
|
||||
BoolAlias,
|
||||
symbolsFoo,
|
||||
fQuux,
|
||||
W,
|
||||
fBar,
|
||||
baz,
|
||||
Quux,
|
||||
qX,
|
||||
Y,
|
||||
Baz,
|
||||
qDo,
|
||||
main,
|
||||
Stringer,
|
||||
String,
|
||||
ABerInterface,
|
||||
B,
|
||||
ABerA,
|
||||
WithEmbeddeds,
|
||||
Do,
|
||||
ABer,
|
||||
ioWriter,
|
||||
WorkspaceSymbolVariableA,
|
||||
WorkspaceSymbolConstantA,
|
||||
workspacesymbolinvariable,
|
||||
WorkspaceSymbolVariableB,
|
||||
WorkspaceSymbolStructB,
|
||||
bBar,
|
||||
)
|
||||
workspacesymbol("workspacesymbolvar",
|
||||
WorkspaceSymbolVariableA,
|
||||
WorkspaceSymbolVariableB,
|
||||
)
|
||||
*/
|
2
internal/lsp/testdata/lsp/summary.txt.golden
vendored
2
internal/lsp/testdata/lsp/summary.txt.golden
vendored
@ -19,7 +19,7 @@ ReferencesCount = 9
|
||||
RenamesCount = 23
|
||||
PrepareRenamesCount = 7
|
||||
SymbolsCount = 3
|
||||
WorkspaceSymbolsCount = 2
|
||||
WorkspaceSymbolsCount = 0
|
||||
FuzzyWorkspaceSymbolsCount = 3
|
||||
CaseSensitiveWorkspaceSymbolsCount = 2
|
||||
SignaturesCount = 23
|
||||
|
Loading…
Reference in New Issue
Block a user