Skip to content

Commit 9e0e9d3

Browse files
authored
fix(56475): Hyperlink in quick info generated by @link jumps to import statement for named or default imports, not symbol definition (#56802)
1 parent 5d3bc98 commit 9e0e9d3

File tree

4 files changed

+147
-16
lines changed

4 files changed

+147
-16
lines changed

src/services/utilities.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2979,10 +2979,11 @@ export function buildLinkParts(link: JSDocLink | JSDocLinkCode | JSDocLinkPlain,
29792979
}
29802980
else {
29812981
const symbol = checker?.getSymbolAtLocation(link.name);
2982+
const targetSymbol = symbol && checker ? getSymbolTarget(symbol, checker) : undefined;
29822983
const suffix = findLinkNameEnd(link.text);
29832984
const name = getTextOfNode(link.name) + link.text.slice(0, suffix);
29842985
const text = skipSeparatorFromLinkText(link.text.slice(suffix));
2985-
const decl = symbol?.valueDeclaration || symbol?.declarations?.[0];
2986+
const decl = targetSymbol?.valueDeclaration || targetSymbol?.declarations?.[0];
29862987
if (decl) {
29872988
parts.push(linkNamePart(name, decl));
29882989
if (text) parts.push(linkTextPart(text));

tests/baselines/reference/jsdocLink3.baseline

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@
8383
"text": "C",
8484
"kind": "linkName",
8585
"target": {
86-
"fileName": "/module1.ts",
86+
"fileName": "/jsdocLink3.ts",
8787
"textSpan": {
88-
"start": 9,
89-
"length": 1
88+
"start": 0,
89+
"length": 18
9090
}
9191
}
9292
},
@@ -111,10 +111,10 @@
111111
"text": "C",
112112
"kind": "linkName",
113113
"target": {
114-
"fileName": "/module1.ts",
114+
"fileName": "/jsdocLink3.ts",
115115
"textSpan": {
116-
"start": 9,
117-
"length": 1
116+
"start": 0,
117+
"length": 18
118118
}
119119
}
120120
},
@@ -134,10 +134,10 @@
134134
"text": "C()",
135135
"kind": "linkName",
136136
"target": {
137-
"fileName": "/module1.ts",
137+
"fileName": "/jsdocLink3.ts",
138138
"textSpan": {
139-
"start": 9,
140-
"length": 1
139+
"start": 0,
140+
"length": 18
141141
}
142142
}
143143
},
@@ -157,10 +157,10 @@
157157
"text": "C",
158158
"kind": "linkName",
159159
"target": {
160-
"fileName": "/module1.ts",
160+
"fileName": "/jsdocLink3.ts",
161161
"textSpan": {
162-
"start": 9,
163-
"length": 1
162+
"start": 0,
163+
"length": 18
164164
}
165165
}
166166
},
@@ -205,10 +205,10 @@
205205
"text": "C",
206206
"kind": "linkName",
207207
"target": {
208-
"fileName": "/module1.ts",
208+
"fileName": "/jsdocLink3.ts",
209209
"textSpan": {
210-
"start": 9,
211-
"length": 1
210+
"start": 0,
211+
"length": 18
212212
}
213213
}
214214
},
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// === QuickInfo ===
2+
=== /b.ts ===
3+
// import A, { B } from "./a";
4+
// /**
5+
// * {@link A}
6+
// * {@link B}
7+
// */
8+
// export default function f() { }
9+
// ^
10+
// | ----------------------------------------------------------------------
11+
// | function f(): void
12+
// | {@link A}
13+
// | {@link B}
14+
// | ----------------------------------------------------------------------
15+
16+
[
17+
{
18+
"marker": {
19+
"fileName": "/b.ts",
20+
"position": 86,
21+
"name": ""
22+
},
23+
"item": {
24+
"kind": "function",
25+
"kindModifiers": "export",
26+
"textSpan": {
27+
"start": 86,
28+
"length": 1
29+
},
30+
"displayParts": [
31+
{
32+
"text": "function",
33+
"kind": "keyword"
34+
},
35+
{
36+
"text": " ",
37+
"kind": "space"
38+
},
39+
{
40+
"text": "f",
41+
"kind": "functionName"
42+
},
43+
{
44+
"text": "(",
45+
"kind": "punctuation"
46+
},
47+
{
48+
"text": ")",
49+
"kind": "punctuation"
50+
},
51+
{
52+
"text": ":",
53+
"kind": "punctuation"
54+
},
55+
{
56+
"text": " ",
57+
"kind": "space"
58+
},
59+
{
60+
"text": "void",
61+
"kind": "keyword"
62+
}
63+
],
64+
"documentation": [
65+
{
66+
"text": "",
67+
"kind": "text"
68+
},
69+
{
70+
"text": "{@link ",
71+
"kind": "link"
72+
},
73+
{
74+
"text": "A",
75+
"kind": "linkName",
76+
"target": {
77+
"fileName": "/a.ts",
78+
"textSpan": {
79+
"start": 0,
80+
"length": 31
81+
}
82+
}
83+
},
84+
{
85+
"text": "}",
86+
"kind": "link"
87+
},
88+
{
89+
"text": "\n",
90+
"kind": "text"
91+
},
92+
{
93+
"text": "{@link ",
94+
"kind": "link"
95+
},
96+
{
97+
"text": "B",
98+
"kind": "linkName",
99+
"target": {
100+
"fileName": "/a.ts",
101+
"textSpan": {
102+
"start": 32,
103+
"length": 23
104+
}
105+
}
106+
},
107+
{
108+
"text": "}",
109+
"kind": "link"
110+
}
111+
]
112+
}
113+
}
114+
]

tests/cases/fourslash/jsdocLink6.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @filename: /a.ts
4+
////export default function A() { }
5+
////export function B() { };
6+
7+
// @Filename: /b.ts
8+
////import A, { B } from "./a";
9+
10+
/////**
11+
//// * {@link A}
12+
//// * {@link B}
13+
//// */
14+
////export default function /**/f() { }
15+
16+
verify.baselineQuickInfo();

0 commit comments

Comments
 (0)