mirror of
https://github.com/golang/go
synced 2024-11-06 07:26:10 -07:00
a5d4502270
* adds gopls command line tool for call hierarchy * adds lsp setup for call hierarchy * adds handler for textDocument/prepareCallHierarchy to display selected identifier and get incoming/outgoing calls for it * setup testing Change-Id: I0a0904abdbe11273a56162b6e5be93b97ceb9c26 Reviewed-on: https://go-review.googlesource.com/c/tools/+/246521 Run-TryBot: Danish Dua <danishdua@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com>
51 lines
1.6 KiB
Go
51 lines
1.6 KiB
Go
// Copyright 2020 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"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
|
|
"golang.org/x/tools/internal/lsp/tests"
|
|
"golang.org/x/tools/internal/span"
|
|
)
|
|
|
|
func (r *runner) CallHierarchy(t *testing.T, spn span.Span, expectedCalls *tests.CallHierarchyResult) {
|
|
var result []string
|
|
// TODO: add expectedCalls.IncomingCalls and expectedCalls.OutgoingCalls to this array once implemented
|
|
result = append(result, fmt.Sprint(spn))
|
|
|
|
sort.Strings(result) // to make tests deterministic
|
|
expect := r.Normalize(strings.Join(result, "\n"))
|
|
|
|
uri := spn.URI()
|
|
filename := uri.Filename()
|
|
target := filename + fmt.Sprintf(":%v:%v", spn.Start().Line(), spn.Start().Column())
|
|
|
|
got, stderr := r.NormalizeGoplsCmd(t, "call_hierarchy", target)
|
|
got = cleanCallHierarchyCmdResult(got)
|
|
if stderr != "" {
|
|
t.Errorf("call_hierarchy failed for %s: %s", target, stderr)
|
|
} else if expect != got {
|
|
t.Errorf("call_hierarchy failed for %s expected:\n%s\ngot:\n%s", target, expect, got)
|
|
}
|
|
}
|
|
|
|
// removes all info except URI and Range from printed output and sorts the result
|
|
// ex: "identifier: func() d at file://callhierarchy/callhierarchy.go:19:6-7" -> "file://callhierarchy/callhierarchy.go:19:6-7"
|
|
func cleanCallHierarchyCmdResult(output string) string {
|
|
var clean []string
|
|
for _, out := range strings.Split(output, "\n") {
|
|
if out == "" {
|
|
continue
|
|
}
|
|
clean = append(clean, out[strings.LastIndex(out, " ")+1:])
|
|
}
|
|
sort.Strings(clean)
|
|
return strings.Join(clean, "\n")
|
|
}
|