mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
@link parses trailing <...> as part of linkName (#46450)
Similar to #46428. Fixes #44818
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -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();
|
||||
Reference in New Issue
Block a user