Skip to content

Commit 98b4ac2

Browse files
authored
@link: format trailing () as part of linkName (microsoft#46428)
Parsing separates the identifier part of the link tag from its text, but the editor should present an identifier followed by `()` as a single identifier since people use that syntax as a function sigil. I prefer `#'` personally, you know, xkcd 297, nudge nudge.
1 parent 48e96f5 commit 98b4ac2

File tree

6 files changed

+341
-20
lines changed

6 files changed

+341
-20
lines changed

src/services/utilities.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,9 +2290,9 @@ namespace ts {
22902290
return displayPart(text, SymbolDisplayPartKind.linkText);
22912291
}
22922292

2293-
export function linkNamePart(name: EntityName | JSDocMemberName, target: Declaration): JSDocLinkDisplayPart {
2293+
export function linkNamePart(text: string, target: Declaration): JSDocLinkDisplayPart {
22942294
return {
2295-
text: getTextOfNode(name),
2295+
text,
22962296
kind: SymbolDisplayPartKind[SymbolDisplayPartKind.linkName],
22972297
target: {
22982298
fileName: getSourceFileOfNode(target).fileName,
@@ -2315,13 +2315,16 @@ namespace ts {
23152315
}
23162316
else {
23172317
const symbol = checker?.getSymbolAtLocation(link.name);
2318+
const trailingParen = link.text.indexOf("()") === 0;
2319+
const name = getTextOfNode(link.name) + (trailingParen ? "()" : "");
2320+
const text = trailingParen ? link.text.slice(2) : link.text;
23182321
const decl = symbol?.valueDeclaration || symbol?.declarations?.[0];
23192322
if (decl) {
2320-
parts.push(linkNamePart(link.name, decl));
2321-
if (link.text) parts.push(linkTextPart(link.text));
2323+
parts.push(linkNamePart(name, decl));
2324+
if (text) parts.push(linkTextPart(text));
23222325
}
23232326
else {
2324-
parts.push(linkTextPart(getTextOfNode(link.name) + " " + link.text));
2327+
parts.push(linkTextPart(name + (trailingParen ? "" : " ") + text));
23252328
}
23262329
}
23272330
parts.push(linkPart("}"));

tests/baselines/reference/jsdocLink1.baseline

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"kind": "link"
108108
},
109109
{
110-
"text": "C",
110+
"text": "C()",
111111
"kind": "linkName",
112112
"target": {
113113
"fileName": "/tests/cases/fourslash/jsdocLink1.ts",
@@ -117,10 +117,6 @@
117117
}
118118
}
119119
},
120-
{
121-
"text": "()",
122-
"kind": "linkText"
123-
},
124120
{
125121
"text": "}",
126122
"kind": "link"

tests/baselines/reference/jsdocLink2.baseline

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"kind": "link"
108108
},
109109
{
110-
"text": "C",
110+
"text": "C()",
111111
"kind": "linkName",
112112
"target": {
113113
"fileName": "/tests/cases/fourslash/jsdocLink2.ts",
@@ -117,10 +117,6 @@
117117
}
118118
}
119119
},
120-
{
121-
"text": "()",
122-
"kind": "linkText"
123-
},
124120
{
125121
"text": "}",
126122
"kind": "link"

tests/baselines/reference/jsdocLink3.baseline

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"kind": "link"
108108
},
109109
{
110-
"text": "C",
110+
"text": "C()",
111111
"kind": "linkName",
112112
"target": {
113113
"fileName": "/jsdocLink3.ts",
@@ -117,10 +117,6 @@
117117
}
118118
}
119119
},
120-
{
121-
"text": "()",
122-
"kind": "linkText"
123-
},
124120
{
125121
"text": "}",
126122
"kind": "link"

0 commit comments

Comments
 (0)