mirror of
https://github.com/golang/go
synced 2024-11-19 04:34:39 -07:00
b8f202ca5e
This adds support for calling links from the gopls command line, e.g. $ gopls links ~/tmp/foo/main.go Optional arguments are: -json, which emits range and uri in JSON With no arguments, a unique list of links are emitted. Updates golang/go#32875 Change-Id: I1e7cbf00a636c05ccf21bd544d9a5b7742d5d70b GitHub-Last-Rev: 7ed1e4612186bce4077d3c73f2407cf6def211d9 GitHub-Pull-Request: golang/tools#181 Reviewed-on: https://go-review.googlesource.com/c/tools/+/203297 Reviewed-by: Rebecca Stambler <rstambler@golang.org> Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
37 lines
957 B
Go
37 lines
957 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 (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"golang.org/x/tools/internal/lsp/cmd"
|
|
"golang.org/x/tools/internal/lsp/protocol"
|
|
"golang.org/x/tools/internal/lsp/tests"
|
|
"golang.org/x/tools/internal/span"
|
|
"golang.org/x/tools/internal/tool"
|
|
)
|
|
|
|
func (r *runner) Link(t *testing.T, uri span.URI, wantLinks []tests.Link) {
|
|
m, err := r.data.Mapper(uri)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
args := []string{"links", "-json", uri.Filename()}
|
|
app := cmd.New("gopls-test", r.data.Config.Dir, r.data.Exported.Config.Env, r.options)
|
|
out := CaptureStdOut(t, func() {
|
|
_ = tool.Run(r.ctx, app, args)
|
|
})
|
|
var got []protocol.DocumentLink
|
|
err = json.Unmarshal([]byte(out), &got)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if diff := tests.DiffLinks(m, wantLinks, got); diff != "" {
|
|
t.Error(diff)
|
|
}
|
|
}
|