mirror of
https://github.com/golang/go
synced 2024-11-19 05:04:43 -07:00
2b544e3f2d
This change adds command line support for references. Example: $ gopls references ~/tmp/foo/main.go:8:6 $ gopls references ~/tmp/foo/main.go:#53 Updates golang/go#32875 Change-Id: I9a0cf6ae8ba0a5c3d4ffc829b96fe3b42297c192 Reviewed-on: https://go-review.googlesource.com/c/tools/+/202178 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
39 lines
1008 B
Go
39 lines
1008 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 (
|
|
"fmt"
|
|
"golang.org/x/tools/internal/lsp/cmd"
|
|
"golang.org/x/tools/internal/tool"
|
|
"testing"
|
|
|
|
"golang.org/x/tools/internal/span"
|
|
)
|
|
|
|
func (r *runner) References(t *testing.T, spn span.Span, itemList []span.Span) {
|
|
var expect string
|
|
for _, i := range itemList {
|
|
expect += fmt.Sprintln(i)
|
|
}
|
|
|
|
uri := spn.URI()
|
|
filename := uri.Filename()
|
|
target := filename + fmt.Sprintf(":%v:%v", spn.Start().Line(), spn.Start().Column())
|
|
|
|
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", "references"}, target))
|
|
if err != nil {
|
|
fmt.Println(spn.Start().Line())
|
|
fmt.Println(err)
|
|
}
|
|
})
|
|
|
|
if expect != got {
|
|
t.Errorf("references failed for %s expected:\n%s\ngot:\n%s", target, expect, got)
|
|
}
|
|
}
|