mirror of
https://github.com/golang/go
synced 2024-11-05 21:46:13 -07:00
20805546e7
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>
26 lines
579 B
Go
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)
|
|
}
|
|
}
|