Debian Codegraph @

gopls/internal/test/marker/testdata/hover/linkable.txt

raw
1 This test checks that we correctly determine pkgsite links for various
2 identifiers.
3
4 We should only produce links that work, meaning the object is reachable via the
5 package's public API.
6
7 -- go.mod --
8 module mod.com
9
10 go 1.18
11 -- p.go --
12 package p
13
14 type E struct {
15 Embed int64
16 }
17
18 // T is in the package scope, and so should be linkable.
19 type T struct{ //@hover("T", "T", T)
20 // Only exported fields should be linkable
21
22 f int64 //@hover("f", "f", f)
23 F int64 //@hover("F", "F", F)
24
25 E
26
27 // TODO(rfindley): is the link here correct? It ignores N.
28 N struct {
29 // Nested fields should also be linkable.
30 Nested int64 //@hover("Nested", "Nested", Nested)
31 }
32 }
33 // M is an exported method, and so should be linkable.
34 func (T) M() {}
35
36 // m is not exported, and so should not be linkable.
37 func (T) m() {}
38
39 var _ = T.m
40
41 func _() {
42 var t T
43
44 // Embedded fields should be linkable.
45 _ = t.Embed //@hover("Embed", "Embed", Embed)
46
47 // Local variables should not be linkable, even if they are capitalized.
48 var X int64 //@hover("X", "X", X)
49 _ = X
50
51 // Local types should not be linkable, even if they are capitalized.
52 type Local struct { //@hover("Local", "Local", Local)
53 E
54 }
55
56 // But the embedded field should still be linkable.
57 var l Local
58 _ = l.Embed //@hover("Embed", "Embed", Embed)
59 }
60 -- @Embed --
61 ```go
62 field Embed int64 // through E
63 ```
64
65 ---
66
67 [`(p.E).Embed` on pkg.go.dev](https://pkg.go.dev/mod.com#E.Embed)
68 -- @F --
69 ```go
70 field F int64 // size=8, offset=8
71 ```
72
73 ---
74
75 @hover("F", "F", F)
76
77
78 ---
79
80 [`(p.T).F` on pkg.go.dev](https://pkg.go.dev/mod.com#T.F)
81 -- @Local --
82 ```go
83 type Local struct { // size=8
84 E
85 }
86 ```
87
88 ---
89
90 Local types should not be linkable, even if they are capitalized.
91
92
93 ```go
94 // Embedded fields:
95 Embed int64 // through E
96 ```
97 -- @Nested --
98 ```go
99 field Nested int64 // size=8, offset=0
100 ```
101
102 ---
103
104 Nested fields should also be linkable.
105 -- @T --
106 ```go
107 type T struct { // size=32 (0x20)
108 f int64 //@hover("f", "f", f)
109 F int64 //@hover("F", "F", F)
110
111 E
112
113 // TODO(rfindley): is the link here correct? It ignores N.
114 N struct {
115 // Nested fields should also be linkable.
116 Nested int64 //@hover("Nested", "Nested", Nested)
117 }
118 }
119 ```
120
121 ---
122
123 T is in the package scope, and so should be linkable.
124
125
126 ```go
127 // Embedded fields:
128 Embed int64 // through E
129 ```
130
131 ```go
132 func (T) M()
133 func (T) m()
134 ```
135
136 ---
137
138 [`p.T` on pkg.go.dev](https://pkg.go.dev/mod.com#T)
139 -- @X --
140 ```go
141 var X int64
142 ```
143
144 ---
145
146 Local variables should not be linkable, even if they are capitalized.
147 -- @f --
148 ```go
149 field f int64 // size=8, offset=0
150 ```
151
152 ---
153
154 @hover("f", "f", f)