diff --git a/gopls/internal/lsp/fake/edit.go b/gopls/internal/lsp/fake/edit.go index e7eeca14662..0b688e7d716 100644 --- a/gopls/internal/lsp/fake/edit.go +++ b/gopls/internal/lsp/fake/edit.go @@ -9,21 +9,6 @@ import ( "golang.org/x/tools/internal/diff" ) -// Location is the editor friendly equivalent of protocol.Location -type Location struct { - Path string - Range protocol.Range -} - -// SymbolInformation is an editor friendly version of -// protocol.SymbolInformation, with location information transformed to byte -// offsets. Field names correspond to the protocol type. -type SymbolInformation struct { - Name string - Kind protocol.SymbolKind - Location Location -} - // NewEdit creates an edit replacing all content between // (startLine, startColumn) and (endLine, endColumn) with text. func NewEdit(startLine, startColumn, endLine, endColumn uint32, text string) protocol.TextEdit { diff --git a/gopls/internal/lsp/fake/editor.go b/gopls/internal/lsp/fake/editor.go index 00bba62997c..7a61785298c 100644 --- a/gopls/internal/lsp/fake/editor.go +++ b/gopls/internal/lsp/fake/editor.go @@ -815,29 +815,11 @@ func (e *Editor) extractFirstPathAndPos(ctx context.Context, locs []protocol.Loc } // Symbol performs a workspace symbol search using query -func (e *Editor) Symbol(ctx context.Context, query string) ([]SymbolInformation, error) { +func (e *Editor) Symbol(ctx context.Context, query string) ([]protocol.SymbolInformation, error) { params := &protocol.WorkspaceSymbolParams{} params.Query = query - resp, err := e.Server.Symbol(ctx, params) - if err != nil { - return nil, fmt.Errorf("symbol: %w", err) - } - var res []SymbolInformation - for _, si := range resp { - ploc := si.Location - path := e.sandbox.Workdir.URIToPath(ploc.URI) - loc := Location{ - Path: path, - Range: ploc.Range, - } - res = append(res, SymbolInformation{ - Name: si.Name, - Kind: si.Kind, - Location: loc, - }) - } - return res, nil + return e.Server.Symbol(ctx, params) } // OrganizeImports requests and performs the source.organizeImports codeAction. diff --git a/gopls/internal/lsp/regtest/wrappers.go b/gopls/internal/lsp/regtest/wrappers.go index 3699597bd71..03f3551ee5f 100644 --- a/gopls/internal/lsp/regtest/wrappers.go +++ b/gopls/internal/lsp/regtest/wrappers.go @@ -178,16 +178,6 @@ func (e *Env) GoToDefinition(name string, pos protocol.Position) (string, protoc return n, p } -// Symbol returns symbols matching query -func (e *Env) Symbol(query string) []fake.SymbolInformation { - e.T.Helper() - r, err := e.Editor.Symbol(e.Ctx, query) - if err != nil { - e.T.Fatal(err) - } - return r -} - // FormatBuffer formats the editor buffer, calling t.Fatal on any error. func (e *Env) FormatBuffer(name string) { e.T.Helper() @@ -394,10 +384,10 @@ func (e *Env) InlayHints(path string) []protocol.InlayHint { return hints } -// WorkspaceSymbol calls workspace/symbol -func (e *Env) WorkspaceSymbol(sym string) []protocol.SymbolInformation { +// Symbol calls workspace/symbol +func (e *Env) Symbol(query string) []protocol.SymbolInformation { e.T.Helper() - ans, err := e.Editor.Symbols(e.Ctx, sym) + ans, err := e.Editor.Symbols(e.Ctx, query) if err != nil { e.T.Fatal(err) } diff --git a/gopls/internal/regtest/bench/workspace_symbols_test.go b/gopls/internal/regtest/bench/workspace_symbols_test.go index fccc8182997..a540dfd2cd0 100644 --- a/gopls/internal/regtest/bench/workspace_symbols_test.go +++ b/gopls/internal/regtest/bench/workspace_symbols_test.go @@ -18,7 +18,7 @@ func BenchmarkWorkspaceSymbols(b *testing.B) { env := benchmarkEnv(b) // Make an initial symbol query to warm the cache. - symbols := env.WorkspaceSymbol(*symbolQuery) + symbols := env.Symbol(*symbolQuery) if testing.Verbose() { fmt.Println("Results:") @@ -30,6 +30,6 @@ func BenchmarkWorkspaceSymbols(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - env.WorkspaceSymbol(*symbolQuery) + env.Symbol(*symbolQuery) } } diff --git a/gopls/internal/regtest/misc/workspace_symbol_test.go b/gopls/internal/regtest/misc/workspace_symbol_test.go index eb150f6094e..33b8147afe4 100644 --- a/gopls/internal/regtest/misc/workspace_symbol_test.go +++ b/gopls/internal/regtest/misc/workspace_symbol_test.go @@ -34,7 +34,7 @@ const C2 = "exclude.go" Run(t, files, func(t *testing.T, env *Env) { env.OpenFile("a.go") - syms := env.WorkspaceSymbol("C") + syms := env.Symbol("C") if got, want := len(syms), 1; got != want { t.Errorf("got %d symbols, want %d", got, want) } @@ -42,7 +42,7 @@ const C2 = "exclude.go" // Opening up an ignored file will result in an overlay with missing // metadata, but this shouldn't break workspace symbols requests. env.OpenFile("exclude.go") - syms = env.WorkspaceSymbol("C") + syms = env.Symbol("C") if got, want := len(syms), 1; got != want { t.Errorf("got %d symbols, want %d", got, want) } @@ -78,7 +78,7 @@ const ( "Fooey", // shorter than Fooest, Foobar "Fooest", } - got := env.WorkspaceSymbol("Foo") + got := env.Symbol("Foo") compareSymbols(t, got, want) }) } @@ -102,11 +102,11 @@ const ( WithOptions( Settings{"symbolMatcher": symbolMatcher}, ).Run(t, files, func(t *testing.T, env *Env) { - compareSymbols(t, env.WorkspaceSymbol("ABC"), []string{"ABC", "AxxBxxCxx"}) - compareSymbols(t, env.WorkspaceSymbol("'ABC"), []string{"ABC"}) - compareSymbols(t, env.WorkspaceSymbol("^mod.com"), []string{"mod.com/a.ABC", "mod.com/a.AxxBxxCxx"}) - compareSymbols(t, env.WorkspaceSymbol("^mod.com Axx"), []string{"mod.com/a.AxxBxxCxx"}) - compareSymbols(t, env.WorkspaceSymbol("C$"), []string{"ABC"}) + compareSymbols(t, env.Symbol("ABC"), []string{"ABC", "AxxBxxCxx"}) + compareSymbols(t, env.Symbol("'ABC"), []string{"ABC"}) + compareSymbols(t, env.Symbol("^mod.com"), []string{"mod.com/a.ABC", "mod.com/a.AxxBxxCxx"}) + compareSymbols(t, env.Symbol("^mod.com Axx"), []string{"mod.com/a.AxxBxxCxx"}) + compareSymbols(t, env.Symbol("C$"), []string{"ABC"}) }) } diff --git a/gopls/internal/regtest/workspace/directoryfilters_test.go b/gopls/internal/regtest/workspace/directoryfilters_test.go index 5db8d897cf8..6e2a15557fd 100644 --- a/gopls/internal/regtest/workspace/directoryfilters_test.go +++ b/gopls/internal/regtest/workspace/directoryfilters_test.go @@ -27,7 +27,7 @@ func TestDirectoryFilters(t *testing.T) { "directoryFilters": []string{"-inner"}, }, ).Run(t, workspaceModule, func(t *testing.T, env *Env) { - syms := env.WorkspaceSymbol("Hi") + syms := env.Symbol("Hi") sort.Slice(syms, func(i, j int) bool { return syms[i].ContainerName < syms[j].ContainerName }) for _, s := range syms { if strings.Contains(s.ContainerName, "inner") { @@ -149,7 +149,7 @@ func TestDirectoryFilters_Wildcard(t *testing.T) { "directoryFilters": filters, }, ).Run(t, workspaceModule, func(t *testing.T, env *Env) { - syms := env.WorkspaceSymbol("Bye") + syms := env.Symbol("Bye") sort.Slice(syms, func(i, j int) bool { return syms[i].ContainerName < syms[j].ContainerName }) for _, s := range syms { if strings.Contains(s.ContainerName, "bye") { diff --git a/gopls/internal/regtest/workspace/standalone_test.go b/gopls/internal/regtest/workspace/standalone_test.go index d7f03469fc6..c9618eb3aeb 100644 --- a/gopls/internal/regtest/workspace/standalone_test.go +++ b/gopls/internal/regtest/workspace/standalone_test.go @@ -54,7 +54,7 @@ func main() { ).Run(t, files, func(t *testing.T, env *Env) { // Initially, gopls should not know about the standalone file as it hasn't // been opened. Therefore, we should only find one symbol 'C'. - syms := env.WorkspaceSymbol("C") + syms := env.Symbol("C") if got, want := len(syms), 1; got != want { t.Errorf("got %d symbols, want %d", got, want) } @@ -95,7 +95,7 @@ func main() { // Having opened the standalone file, we should find its symbols in the // workspace. - syms = env.WorkspaceSymbol("C") + syms = env.Symbol("C") if got, want := len(syms), 2; got != want { t.Fatalf("got %d symbols, want %d", got, want) }