You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In
type myAlias = someType
type _ struct {
myAlias
}
Previously running "definition" on the "myAlias" field would take you
to the definition of "someType" instead of "myAlias". This is because
we were using the field's (*types.Var).Type() which has already
forgotten it is an alias. Fix by instead looking up the field name
ident in types.Info.Uses which yields the *types.TypeName (for the
type alias).
Fixesgolang/go#42254.
Change-Id: Idbbd0c49ba6f701f52568b3ab1143d8e24037c69
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272186
Run-TryBot: Muir Manders <muir@mnd.rs>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Muir Manders <muir@mnd.rs>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Copy file name to clipboardExpand all lines: internal/lsp/testdata/godef/b/b.go.golden
+72-42Lines changed: 72 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -143,11 +143,12 @@ func a.AStuff()
143
143
144
144
[`a.AStuff` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/a?utm_source=gopls#AStuff)
145
145
-- S1-definition --
146
-
godef/b/b.go:25:6-8: defined here as ```go
146
+
godef/b/b.go:27:6-8: defined here as ```go
147
147
type S1 struct {
148
-
F1 int //@mark(S1F1, "F1")
149
-
S2 //@godef("S2", S2),mark(S1S2, "S2")
150
-
a.A //@godef("A", AString)
148
+
F1 int //@mark(S1F1, "F1")
149
+
S2 //@godef("S2", S2),mark(S1S2, "S2")
150
+
a.A //@godef("A", AString)
151
+
aAlias //@godef("a", aAlias)
151
152
}
152
153
```
153
154
@@ -157,31 +158,32 @@ type S1 struct {
157
158
"span": {
158
159
"uri": "file://godef/b/b.go",
159
160
"start": {
160
-
"line": 25,
161
+
"line": 27,
161
162
"column": 6,
162
-
"offset": 521
163
+
"offset": 566
163
164
},
164
165
"end": {
165
-
"line": 25,
166
+
"line": 27,
166
167
"column": 8,
167
-
"offset": 523
168
+
"offset": 568
168
169
}
169
170
},
170
-
"description": "```go\ntype S1 struct {\n\tF1 int //@mark(S1F1, \"F1\")\n\tS2 //@godef(\"S2\", S2),mark(S1S2, \"S2\")\n\ta.A //@godef(\"A\", AString)\n}\n```\n\n[`b.S1` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/b?utm_source=gopls#S1)"
171
+
"description": "```go\ntype S1 struct {\n\tF1 int //@mark(S1F1, \"F1\")\n\tS2 //@godef(\"S2\", S2),mark(S1S2, \"S2\")\n\ta.A //@godef(\"A\", AString)\n\taAlias //@godef(\"a\", aAlias)\n}\n```\n\n[`b.S1` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/b?utm_source=gopls#S1)"
171
172
}
172
173
173
174
-- S1-hover --
174
175
```go
175
176
type S1 struct {
176
-
F1 int //@mark(S1F1, "F1")
177
-
S2 //@godef("S2", S2),mark(S1S2, "S2")
178
-
a.A //@godef("A", AString)
177
+
F1 int //@mark(S1F1, "F1")
178
+
S2 //@godef("S2", S2),mark(S1S2, "S2")
179
+
a.A //@godef("A", AString)
180
+
aAlias //@godef("a", aAlias)
179
181
}
180
182
```
181
183
182
184
[`b.S1` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/b?utm_source=gopls#S1)
183
185
-- S1F1-definition --
184
-
godef/b/b.go:26:2-4: defined here as ```go
186
+
godef/b/b.go:28:2-4: defined here as ```go
185
187
field F1 int
186
188
```
187
189
@@ -193,14 +195,14 @@ field F1 int
193
195
"span": {
194
196
"uri": "file://godef/b/b.go",
195
197
"start": {
196
-
"line": 26,
198
+
"line": 28,
197
199
"column": 2,
198
-
"offset": 540
200
+
"offset": 585
199
201
},
200
202
"end": {
201
-
"line": 26,
203
+
"line": 28,
202
204
"column": 4,
203
-
"offset": 542
205
+
"offset": 587
204
206
}
205
207
},
206
208
"description": "```go\nfield F1 int\n```\n\n[`(b.S1).F1` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/b?utm_source=gopls#S1.F1)\n\n\\@mark\\(S1F1, \\\"F1\\\"\\)"
@@ -215,7 +217,7 @@ field F1 int
215
217
216
218
\@mark\(S1F1, \"F1\"\)
217
219
-- S1S2-definition --
218
-
godef/b/b.go:27:2-4: defined here as ```go
220
+
godef/b/b.go:29:2-4: defined here as ```go
219
221
field S2 S2
220
222
```
221
223
@@ -227,14 +229,14 @@ field S2 S2
227
229
"span": {
228
230
"uri": "file://godef/b/b.go",
229
231
"start": {
230
-
"line": 27,
232
+
"line": 29,
231
233
"column": 2,
232
-
"offset": 569
234
+
"offset": 617
233
235
},
234
236
"end": {
235
-
"line": 27,
237
+
"line": 29,
236
238
"column": 4,
237
-
"offset": 571
239
+
"offset": 619
238
240
}
239
241
},
240
242
"description": "```go\nfield S2 S2\n```\n\n[`(b.S1).S2` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/b?utm_source=gopls#S1.S2)\n\n\\@godef\\(\\\"S2\\\", S2\\),mark\\(S1S2, \\\"S2\\\"\\)"
@@ -249,7 +251,7 @@ field S2 S2
249
251
250
252
\@godef\(\"S2\", S2\),mark\(S1S2, \"S2\"\)
251
253
-- S2-definition --
252
-
godef/b/b.go:31:6-8: defined here as ```go
254
+
godef/b/b.go:34:6-8: defined here as ```go
253
255
type S2 struct {
254
256
F1 string //@mark(S2F1, "F1")
255
257
F2 int //@mark(S2F2, "F2")
@@ -263,14 +265,14 @@ type S2 struct {
263
265
"span": {
264
266
"uri": "file://godef/b/b.go",
265
267
"start": {
266
-
"line": 31,
268
+
"line": 34,
267
269
"column": 6,
268
-
"offset": 653
270
+
"offset": 741
269
271
},
270
272
"end": {
271
-
"line": 31,
273
+
"line": 34,
272
274
"column": 8,
273
-
"offset": 655
275
+
"offset": 743
274
276
}
275
277
},
276
278
"description": "```go\ntype S2 struct {\n\tF1 string //@mark(S2F1, \"F1\")\n\tF2 int //@mark(S2F2, \"F2\")\n\t*a.A //@godef(\"A\", AString),godef(\"a\",AImport)\n}\n```\n\n[`b.S2` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/b?utm_source=gopls#S2)"
@@ -287,7 +289,7 @@ type S2 struct {
287
289
288
290
[`b.S2` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/b?utm_source=gopls#S2)
289
291
-- S2F1-definition --
290
-
godef/b/b.go:32:2-4: defined here as ```go
292
+
godef/b/b.go:35:2-4: defined here as ```go
291
293
field F1 string
292
294
```
293
295
@@ -299,14 +301,14 @@ field F1 string
299
301
"span": {
300
302
"uri": "file://godef/b/b.go",
301
303
"start": {
302
-
"line": 32,
304
+
"line": 35,
303
305
"column": 2,
304
-
"offset": 672
306
+
"offset": 760
305
307
},
306
308
"end": {
307
-
"line": 32,
309
+
"line": 35,
308
310
"column": 4,
309
-
"offset": 674
311
+
"offset": 762
310
312
}
311
313
},
312
314
"description": "```go\nfield F1 string\n```\n\n[`(b.S2).F1` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/b?utm_source=gopls#S2.F1)\n\n\\@mark\\(S2F1, \\\"F1\\\"\\)"
@@ -321,7 +323,7 @@ field F1 string
321
323
322
324
\@mark\(S2F1, \"F1\"\)
323
325
-- S2F2-definition --
324
-
godef/b/b.go:33:2-4: defined here as ```go
326
+
godef/b/b.go:36:2-4: defined here as ```go
325
327
field F2 int
326
328
```
327
329
@@ -333,14 +335,14 @@ field F2 int
333
335
"span": {
334
336
"uri": "file://godef/b/b.go",
335
337
"start": {
336
-
"line": 33,
338
+
"line": 36,
337
339
"column": 2,
338
-
"offset": 705
340
+
"offset": 793
339
341
},
340
342
"end": {
341
-
"line": 33,
343
+
"line": 36,
342
344
"column": 4,
343
-
"offset": 707
345
+
"offset": 795
344
346
}
345
347
},
346
348
"description": "```go\nfield F2 int\n```\n\n[`(b.S2).F2` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/b?utm_source=gopls#S2.F2)\n\n\\@mark\\(S2F2, \\\"F2\\\"\\)"
@@ -354,8 +356,36 @@ field F2 int
354
356
[`(b.S2).F2` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/b?utm_source=gopls#S2.F2)
"description": "```go\nconst X untyped int = 0\n```\n\n[`b.X` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/b?utm_source=gopls#X)\n\n\\@mark\\(bX, \\\"X\\\"\\),godef\\(\\\"X\\\", bX\\)"
Copy file name to clipboardExpand all lines: internal/lsp/testdata/godef/b/c.go.golden
+19-17Lines changed: 19 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,10 @@
1
1
-- S1-definition --
2
-
godef/b/b.go:25:6-8: defined here as ```go
2
+
godef/b/b.go:27:6-8: defined here as ```go
3
3
type S1 struct {
4
-
F1 int //@mark(S1F1, "F1")
5
-
S2 //@godef("S2", S2),mark(S1S2, "S2")
6
-
a.A //@godef("A", AString)
4
+
F1 int //@mark(S1F1, "F1")
5
+
S2 //@godef("S2", S2),mark(S1S2, "S2")
6
+
a.A //@godef("A", AString)
7
+
aAlias //@godef("a", aAlias)
7
8
}
8
9
```
9
10
@@ -13,31 +14,32 @@ type S1 struct {
13
14
"span": {
14
15
"uri": "file://godef/b/b.go",
15
16
"start": {
16
-
"line": 25,
17
+
"line": 27,
17
18
"column": 6,
18
-
"offset": 521
19
+
"offset": 566
19
20
},
20
21
"end": {
21
-
"line": 25,
22
+
"line": 27,
22
23
"column": 8,
23
-
"offset": 523
24
+
"offset": 568
24
25
}
25
26
},
26
-
"description": "```go\ntype S1 struct {\n\tF1 int //@mark(S1F1, \"F1\")\n\tS2 //@godef(\"S2\", S2),mark(S1S2, \"S2\")\n\ta.A //@godef(\"A\", AString)\n}\n```\n\n[`b.S1` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/b?utm_source=gopls#S1)"
27
+
"description": "```go\ntype S1 struct {\n\tF1 int //@mark(S1F1, \"F1\")\n\tS2 //@godef(\"S2\", S2),mark(S1S2, \"S2\")\n\ta.A //@godef(\"A\", AString)\n\taAlias //@godef(\"a\", aAlias)\n}\n```\n\n[`b.S1` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/b?utm_source=gopls#S1)"
27
28
}
28
29
29
30
-- S1-hover --
30
31
```go
31
32
type S1 struct {
32
-
F1 int //@mark(S1F1, "F1")
33
-
S2 //@godef("S2", S2),mark(S1S2, "S2")
34
-
a.A //@godef("A", AString)
33
+
F1 int //@mark(S1F1, "F1")
34
+
S2 //@godef("S2", S2),mark(S1S2, "S2")
35
+
a.A //@godef("A", AString)
36
+
aAlias //@godef("a", aAlias)
35
37
}
36
38
```
37
39
38
40
[`b.S1` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/b?utm_source=gopls#S1)
39
41
-- S1F1-definition --
40
-
godef/b/b.go:26:2-4: defined here as ```go
42
+
godef/b/b.go:28:2-4: defined here as ```go
41
43
field F1 int
42
44
```
43
45
@@ -49,14 +51,14 @@ field F1 int
49
51
"span": {
50
52
"uri": "file://godef/b/b.go",
51
53
"start": {
52
-
"line": 26,
54
+
"line": 28,
53
55
"column": 2,
54
-
"offset": 540
56
+
"offset": 585
55
57
},
56
58
"end": {
57
-
"line": 26,
59
+
"line": 28,
58
60
"column": 4,
59
-
"offset": 542
61
+
"offset": 587
60
62
}
61
63
},
62
64
"description": "```go\nfield F1 int\n```\n\n[`(b.S1).F1` on pkg.go.dev](https://pkg.go.dev/golang.org/x/tools/internal/lsp/godef/b?utm_source=gopls#S1.F1)\n\n\\@mark\\(S1F1, \\\"F1\\\"\\)"
0 commit comments