1
0
mirror of https://github.com/golang/go synced 2024-11-18 23:44:43 -07:00
go/internal/lsp/cmd/test/highlight.go
Francesco Renzi 20805546e7 tools/gopls: add cmd support for highlight
This change adds command line support for highlight.
Provided with an identifier position, it will display
the list of highlights for that within the same file.

Example:

$ gopls highlight ~/tmp/foo/main.go:3:9
$
$ 3:9-6:0
$ 10:22-11:32
$ 12:10-12:9
$ 12:20-30:0

Updates golang/go#32875

Change-Id: I5de73d9fbd9bcc59a3f62e7e9a1331bc3866bc75
Reviewed-on: https://go-review.googlesource.com/c/tools/+/207291
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-11-26 20:36:08 +00:00

26 lines
579 B
Go

package cmdtest
import (
"testing"
"fmt"
"golang.org/x/tools/internal/span"
)
func (r *runner) Highlight(t *testing.T, spn span.Span, spans []span.Span) {
var expect string
for _, l := range spans {
expect += fmt.Sprintln(l)
}
expect = r.Normalize(expect)
uri := spn.URI()
filename := uri.Filename()
target := filename + ":" + fmt.Sprint(spn.Start().Line()) + ":" + fmt.Sprint(spn.Start().Column())
got, _ := r.NormalizeGoplsCmd(t, "highlight", target)
if expect != got {
t.Errorf("highlight failed for %s expected:\n%s\ngot:\n%s", target, expect, got)
}
}