mirror of
https://github.com/golang/go
synced 2024-11-19 01:34:40 -07:00
f02a19dded
This change adds command line support for symbols. Symbols are formatted as '{name} {type} {range}', with children being preceded by a \t. Example: $ gopls symbols ~/tmp/foo/main.go $ $ x Variable 7:5-7:6 $ y Constant 9:7-9:8 $ Quux Struct 29:6-29:10 $ Do Method 37:16-37:18 $ X Field 30:2-30:3 $ Y Field 30:5-30:6 Updates golang/go#32875 Change-Id: I1272fce733fb12b67e3d6fb948f5bf3de4ca2ca1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/203609 Run-TryBot: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
34 lines
955 B
Go
34 lines
955 B
Go
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cmdtest
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"fmt"
|
|
|
|
"golang.org/x/tools/internal/lsp/cmd"
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
"golang.org/x/tools/internal/span"
|
|
"golang.org/x/tools/internal/tool"
|
|
)
|
|
|
|
func (r *runner) Symbols(t *testing.T, uri span.URI, expectedSymbols []protocol.DocumentSymbol) {
|
|
filename := uri.Filename()
|
|
app := cmd.New("gopls-test", r.data.Config.Dir, r.data.Config.Env, r.options)
|
|
got := CaptureStdOut(t, func() {
|
|
err := tool.Run(r.ctx, app, append([]string{"-remote=internal", "symbols"}, filename))
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
})
|
|
expect := string(r.data.Golden("symbols", filename, func() ([]byte, error) {
|
|
return []byte(got), nil
|
|
}))
|
|
if expect != got {
|
|
t.Errorf("symbols failed for %s expected:\n%s\ngot:\n%s", filename, expect, got)
|
|
}
|
|
}
|