Skip to content

Commit

Permalink
gopls/internal/lsp/tests: use the mustRange helper in more places
Browse files Browse the repository at this point in the history
In order to narrow usage of tests.Data.t, use the mustRange helper in
more places.

For golang/go#54845

Change-Id: I446ca520fa76afb2bc10c1fd5a5765859176dd6a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/432336
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
  • Loading branch information
findleyr committed Sep 23, 2022
1 parent c7ac942 commit 88b5529
Showing 1 changed file with 4 additions and 39 deletions.
43 changes: 4 additions & 39 deletions gopls/internal/lsp/tests/tests.go
Expand Up @@ -1123,19 +1123,8 @@ func (data *Data) Golden(t *testing.T, tag, target string, update func() ([]byte
}

func (data *Data) collectCodeLens(spn span.Span, title, cmd string) {
if _, ok := data.CodeLens[spn.URI()]; !ok {
data.CodeLens[spn.URI()] = []protocol.CodeLens{}
}
m, err := data.Mapper(spn.URI())
if err != nil {
data.t.Fatalf("Mapper: %v", err)
}
rng, err := m.Range(spn)
if err != nil {
data.t.Fatalf("Range: %v", err)
}
data.CodeLens[spn.URI()] = append(data.CodeLens[spn.URI()], protocol.CodeLens{
Range: rng,
Range: data.mustRange(spn),
Command: protocol.Command{
Title: title,
Command: cmd,
Expand All @@ -1144,15 +1133,6 @@ func (data *Data) collectCodeLens(spn span.Span, title, cmd string) {
}

func (data *Data) collectDiagnostics(spn span.Span, msgSource, msgPattern, msgSeverity string) {
m, err := data.Mapper(spn.URI())
if err != nil {
data.t.Fatalf("Mapper: %v", err)
}
rng, err := m.Range(spn)
if err != nil {
data.t.Fatalf("Range: %v", err)
}

severity := protocol.SeverityError
switch msgSeverity {
case "error":
Expand All @@ -1166,7 +1146,7 @@ func (data *Data) collectDiagnostics(spn span.Span, msgSource, msgPattern, msgSe
}

data.Diagnostics[spn.URI()] = append(data.Diagnostics[spn.URI()], &source.Diagnostic{
Range: rng,
Range: data.mustRange(spn),
Severity: severity,
Source: source.DiagnosticSource(msgSource),
Message: msgPattern,
Expand Down Expand Up @@ -1275,14 +1255,7 @@ func (data *Data) collectImplementations(src span.Span, targets []span.Span) {

func (data *Data) collectIncomingCalls(src span.Span, calls []span.Span) {
for _, call := range calls {
m, err := data.Mapper(call.URI())
if err != nil {
data.t.Fatal(err)
}
rng, err := m.Range(call)
if err != nil {
data.t.Fatal(err)
}
rng := data.mustRange(call)
// we're only comparing protocol.range
if data.CallHierarchy[src] != nil {
data.CallHierarchy[src].IncomingCalls = append(data.CallHierarchy[src].IncomingCalls,
Expand All @@ -1305,19 +1278,11 @@ func (data *Data) collectOutgoingCalls(src span.Span, calls []span.Span) {
data.CallHierarchy[src] = &CallHierarchyResult{}
}
for _, call := range calls {
m, err := data.Mapper(call.URI())
if err != nil {
data.t.Fatal(err)
}
rng, err := m.Range(call)
if err != nil {
data.t.Fatal(err)
}
// we're only comparing protocol.range
data.CallHierarchy[src].OutgoingCalls = append(data.CallHierarchy[src].OutgoingCalls,
protocol.CallHierarchyItem{
URI: protocol.DocumentURI(call.URI()),
Range: rng,
Range: data.mustRange(call),
})
}
}
Expand Down

0 comments on commit 88b5529

Please sign in to comment.