| 1 |
This test checks call hierarchy queries. |
| 2 |
|
| 3 |
-ignore_extra_diags due to the initialization cycle. |
| 4 |
|
| 5 |
-- flags -- |
| 6 |
-ignore_extra_diags |
| 7 |
|
| 8 |
-- go.mod -- |
| 9 |
module golang.org/lsptests/callhierarchy |
| 10 |
|
| 11 |
-- incoming/incoming.go -- |
| 12 |
package incoming |
| 13 |
|
| 14 |
import "golang.org/lsptests/callhierarchy" |
| 15 |
|
| 16 |
// A is exported to test incoming calls across packages |
| 17 |
func A() { //@loc(incomingA, "A") |
| 18 |
callhierarchy.D() |
| 19 |
} |
| 20 |
|
| 21 |
-- outgoing/outgoing.go -- |
| 22 |
package outgoing |
| 23 |
|
| 24 |
// B is exported to test outgoing calls across packages |
| 25 |
func B() { //@loc(outgoingB, "B") |
| 26 |
} |
| 27 |
|
| 28 |
-- hierarchy.go -- |
| 29 |
package callhierarchy //@loc(hPkg, "callhierarchy") |
| 30 |
|
| 31 |
import "golang.org/lsptests/callhierarchy/outgoing" |
| 32 |
|
| 33 |
func a() { //@loc(hA, "a") |
| 34 |
D() |
| 35 |
} |
| 36 |
|
| 37 |
func b() { //@loc(hB, "b") |
| 38 |
D() |
| 39 |
} |
| 40 |
|
| 41 |
// C is an exported function |
| 42 |
func C() { //@loc(hC, "C") |
| 43 |
D() |
| 44 |
D() |
| 45 |
} |
| 46 |
|
| 47 |
// To test hierarchy across function literals |
| 48 |
var x = func() { D() } //@loc(hX, "x"),loc(hXGlobal, "x") |
| 49 |
|
| 50 |
// D is exported to test incoming/outgoing calls across packages |
| 51 |
func D() { //@ loc(hD, "D"), incomingcalls(hD, hA, hB, hC, hXGlobal, incomingA), outgoingcalls(hD, hE, hF, hG, hH, hI, Generic, outgoingB) |
| 52 |
e() |
| 53 |
x() |
| 54 |
F() |
| 55 |
outgoing.B() |
| 56 |
|
| 57 |
func() { |
| 58 |
g() |
| 59 |
}() |
| 60 |
|
| 61 |
var i Interface = impl{} |
| 62 |
i.H() |
| 63 |
i.I() |
| 64 |
|
| 65 |
s := Struct{} |
| 66 |
s.J() |
| 67 |
s.K() |
| 68 |
|
| 69 |
Generic[string]() |
| 70 |
} |
| 71 |
|
| 72 |
func e() {} //@loc(hE, "e") |
| 73 |
|
| 74 |
// F is an exported function |
| 75 |
func F() {} //@loc(hF, "F") |
| 76 |
|
| 77 |
func g() {} //@loc(hG, "g") |
| 78 |
|
| 79 |
type Interface interface { |
| 80 |
H() //@loc(hH, "H") |
| 81 |
I() //@loc(hI, "I") |
| 82 |
} |
| 83 |
|
| 84 |
type impl struct{} |
| 85 |
|
| 86 |
func (i impl) H() {} |
| 87 |
func (i impl) I() {} |
| 88 |
|
| 89 |
type Struct struct { |
| 90 |
J func() //@loc(hJ, "J") |
| 91 |
K func() //@loc(hK, "K") |
| 92 |
} |
| 93 |
|
| 94 |
func Generic[T any]() //@loc(Generic, "Generic") |