Skip to content

@link parses trailing <...> as part of linkName #46450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2315,22 +2315,36 @@ namespace ts {
}
else {
const symbol = checker?.getSymbolAtLocation(link.name);
const trailingParen = link.text.indexOf("()") === 0;
const name = getTextOfNode(link.name) + (trailingParen ? "()" : "");
const text = trailingParen ? link.text.slice(2) : link.text;
const suffix = findLinkNameEnd(link.text);
const name = getTextOfNode(link.name) + link.text.slice(0, suffix);
const text = link.text.slice(suffix);
const decl = symbol?.valueDeclaration || symbol?.declarations?.[0];
if (decl) {
parts.push(linkNamePart(name, decl));
if (text) parts.push(linkTextPart(text));
}
else {
parts.push(linkTextPart(name + (trailingParen ? "" : " ") + text));
parts.push(linkTextPart(name + (suffix ? "" : " ") + text));
}
}
parts.push(linkPart("}"));
return parts;
}

function findLinkNameEnd(text: string) {
if (text.indexOf("()") === 0) return 2;
if (text[0] !== "<") return 0;
let brackets = 0;
let i = 0;
while (i < text.length) {
if (text[i] === "<") brackets++;
if (text[i] === ">") brackets--;
i++;
if (!brackets) return i;
}
return 0;
}

const carriageReturnLineFeed = "\r\n";
/**
* The default is CRLF.
Expand Down
227 changes: 227 additions & 0 deletions tests/baselines/reference/quickInfoLink3.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
[
{
"marker": {
"fileName": "/tests/cases/fourslash/quickInfoLink3.ts",
"position": 169,
"name": ""
},
"quickInfo": {
"kind": "method",
"kindModifiers": "",
"textSpan": {
"start": 166,
"length": 3
},
"displayParts": [
{
"text": "(",
"kind": "punctuation"
},
{
"text": "method",
"kind": "text"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "Foo",
"kind": "className"
},
{
"text": "<",
"kind": "punctuation"
},
{
"text": "T",
"kind": "typeParameterName"
},
{
"text": ">",
"kind": "punctuation"
},
{
"text": ".",
"kind": "punctuation"
},
{
"text": "bar",
"kind": "methodName"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "void",
"kind": "keyword"
}
],
"documentation": [
{
"text": "",
"kind": "text"
},
{
"text": "{@link ",
"kind": "link"
},
{
"text": "Foo",
"kind": "linkName",
"target": {
"fileName": "/tests/cases/fourslash/quickInfoLink3.ts",
"textSpan": {
"start": 0,
"length": 175
}
}
},
{
"text": "}",
"kind": "link"
},
{
"text": "\n",
"kind": "text"
},
{
"text": "{@link ",
"kind": "link"
},
{
"text": "Foo<T>",
"kind": "linkName",
"target": {
"fileName": "/tests/cases/fourslash/quickInfoLink3.ts",
"textSpan": {
"start": 0,
"length": 175
}
}
},
{
"text": "}",
"kind": "link"
},
{
"text": "\n",
"kind": "text"
},
{
"text": "{@link ",
"kind": "link"
},
{
"text": "Foo<Array<X>>",
"kind": "linkName",
"target": {
"fileName": "/tests/cases/fourslash/quickInfoLink3.ts",
"textSpan": {
"start": 0,
"length": 175
}
}
},
{
"text": "}",
"kind": "link"
},
{
"text": "\n",
"kind": "text"
},
{
"text": "{@link ",
"kind": "link"
},
{
"text": "Foo<>",
"kind": "linkName",
"target": {
"fileName": "/tests/cases/fourslash/quickInfoLink3.ts",
"textSpan": {
"start": 0,
"length": 175
}
}
},
{
"text": "}",
"kind": "link"
},
{
"text": "\n",
"kind": "text"
},
{
"text": "{@link ",
"kind": "link"
},
{
"text": "Foo",
"kind": "linkName",
"target": {
"fileName": "/tests/cases/fourslash/quickInfoLink3.ts",
"textSpan": {
"start": 0,
"length": 175
}
}
},
{
"text": ">",
"kind": "linkText"
},
{
"text": "}",
"kind": "link"
},
{
"text": "\n",
"kind": "text"
},
{
"text": "{@link ",
"kind": "link"
},
{
"text": "Foo",
"kind": "linkName",
"target": {
"fileName": "/tests/cases/fourslash/quickInfoLink3.ts",
"textSpan": {
"start": 0,
"length": 175
}
}
},
{
"text": "<",
"kind": "linkText"
},
{
"text": "}",
"kind": "link"
}
]
}
}
]
16 changes: 16 additions & 0 deletions tests/cases/fourslash/quickInfoLink3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
///<reference path="fourslash.ts" />

//// class Foo<T> {
//// /**
//// * {@link Foo}
//// * {@link Foo<T>}
//// * {@link Foo<Array<X>>}
//// * {@link Foo<>}
//// * {@link Foo>}
//// * {@link Foo<}
//// */
//// bar/**/(){}
//// }

verify.noErrors()
verify.baselineQuickInfo();