From 2c247d21a461b51644925efadef2e65876e43a5b Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 15 Dec 2023 23:45:26 +0200 Subject: [PATCH] fix(56475): go to target symbol from jsdoc link tag --- src/services/utilities.ts | 3 +- tests/baselines/reference/jsdocLink3.baseline | 30 ++--- tests/baselines/reference/jsdocLink6.baseline | 114 ++++++++++++++++++ tests/cases/fourslash/jsdocLink6.ts | 16 +++ 4 files changed, 147 insertions(+), 16 deletions(-) create mode 100644 tests/baselines/reference/jsdocLink6.baseline create mode 100644 tests/cases/fourslash/jsdocLink6.ts diff --git a/src/services/utilities.ts b/src/services/utilities.ts index bb505008bedb8..b87344d12b618 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -2977,10 +2977,11 @@ export function buildLinkParts(link: JSDocLink | JSDocLinkCode | JSDocLinkPlain, } else { const symbol = checker?.getSymbolAtLocation(link.name); + const targetSymbol = symbol && checker ? getSymbolTarget(symbol, checker) : undefined; const suffix = findLinkNameEnd(link.text); const name = getTextOfNode(link.name) + link.text.slice(0, suffix); const text = skipSeparatorFromLinkText(link.text.slice(suffix)); - const decl = symbol?.valueDeclaration || symbol?.declarations?.[0]; + const decl = targetSymbol?.valueDeclaration || targetSymbol?.declarations?.[0]; if (decl) { parts.push(linkNamePart(name, decl)); if (text) parts.push(linkTextPart(text)); diff --git a/tests/baselines/reference/jsdocLink3.baseline b/tests/baselines/reference/jsdocLink3.baseline index c3f9432976119..01c167788365a 100644 --- a/tests/baselines/reference/jsdocLink3.baseline +++ b/tests/baselines/reference/jsdocLink3.baseline @@ -83,10 +83,10 @@ "text": "C", "kind": "linkName", "target": { - "fileName": "/module1.ts", + "fileName": "/jsdocLink3.ts", "textSpan": { - "start": 9, - "length": 1 + "start": 0, + "length": 18 } } }, @@ -111,10 +111,10 @@ "text": "C", "kind": "linkName", "target": { - "fileName": "/module1.ts", + "fileName": "/jsdocLink3.ts", "textSpan": { - "start": 9, - "length": 1 + "start": 0, + "length": 18 } } }, @@ -134,10 +134,10 @@ "text": "C()", "kind": "linkName", "target": { - "fileName": "/module1.ts", + "fileName": "/jsdocLink3.ts", "textSpan": { - "start": 9, - "length": 1 + "start": 0, + "length": 18 } } }, @@ -157,10 +157,10 @@ "text": "C", "kind": "linkName", "target": { - "fileName": "/module1.ts", + "fileName": "/jsdocLink3.ts", "textSpan": { - "start": 9, - "length": 1 + "start": 0, + "length": 18 } } }, @@ -205,10 +205,10 @@ "text": "C", "kind": "linkName", "target": { - "fileName": "/module1.ts", + "fileName": "/jsdocLink3.ts", "textSpan": { - "start": 9, - "length": 1 + "start": 0, + "length": 18 } } }, diff --git a/tests/baselines/reference/jsdocLink6.baseline b/tests/baselines/reference/jsdocLink6.baseline new file mode 100644 index 0000000000000..c7fee2ac65b9f --- /dev/null +++ b/tests/baselines/reference/jsdocLink6.baseline @@ -0,0 +1,114 @@ +// === QuickInfo === +=== /b.ts === +// import A, { B } from "./a"; +// /** +// * {@link A} +// * {@link B} +// */ +// export default function f() { } +// ^ +// | ---------------------------------------------------------------------- +// | function f(): void +// | {@link A} +// | {@link B} +// | ---------------------------------------------------------------------- + +[ + { + "marker": { + "fileName": "/b.ts", + "position": 86, + "name": "" + }, + "item": { + "kind": "function", + "kindModifiers": "export", + "textSpan": { + "start": 86, + "length": 1 + }, + "displayParts": [ + { + "text": "function", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "f", + "kind": "functionName" + }, + { + "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": "A", + "kind": "linkName", + "target": { + "fileName": "/a.ts", + "textSpan": { + "start": 0, + "length": 31 + } + } + }, + { + "text": "}", + "kind": "link" + }, + { + "text": "\n", + "kind": "text" + }, + { + "text": "{@link ", + "kind": "link" + }, + { + "text": "B", + "kind": "linkName", + "target": { + "fileName": "/a.ts", + "textSpan": { + "start": 32, + "length": 23 + } + } + }, + { + "text": "}", + "kind": "link" + } + ] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/jsdocLink6.ts b/tests/cases/fourslash/jsdocLink6.ts new file mode 100644 index 0000000000000..459066fbabe01 --- /dev/null +++ b/tests/cases/fourslash/jsdocLink6.ts @@ -0,0 +1,16 @@ +/// + +// @filename: /a.ts +////export default function A() { } +////export function B() { }; + +// @Filename: /b.ts +////import A, { B } from "./a"; + +/////** +//// * {@link A} +//// * {@link B} +//// */ +////export default function /**/f() { } + +verify.baselineQuickInfo();