From 320e628a6d98ef5689a239f546cdb20ecccd8dc7 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 9 May 2023 02:55:04 +0300 Subject: [PATCH] fix(53424): in code documentation is not working upon import if function expression reuse function type (#53964) --- src/services/symbolDisplay.ts | 5 +- .../reference/quickInfoJsDocAlias.baseline | 91 +++++++++++++++++++ tests/cases/fourslash/quickInfoJsDocAlias.ts | 15 +++ 3 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/quickInfoJsDocAlias.baseline create mode 100644 tests/cases/fourslash/quickInfoJsDocAlias.ts diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index 25c04c712f5..f9db3831f3b 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -535,12 +535,12 @@ export function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker: Typ // don't use symbolFlags since getAliasedSymbol requires the flag on the symbol itself if (symbol.flags & SymbolFlags.Alias) { prefixNextMeaning(); - if (!hasAddedSymbolInfo) { + if (!hasAddedSymbolInfo || documentation.length === 0 && tags.length === 0) { const resolvedSymbol = typeChecker.getAliasedSymbol(symbol); if (resolvedSymbol !== symbol && resolvedSymbol.declarations && resolvedSymbol.declarations.length > 0) { const resolvedNode = resolvedSymbol.declarations[0]; const declarationName = getNameOfDeclaration(resolvedNode); - if (declarationName) { + if (declarationName && !hasAddedSymbolInfo) { const isExternalModuleDeclaration = isModuleWithStringLiteralName(resolvedNode) && hasSyntacticModifier(resolvedNode, ModifierFlags.Ambient); @@ -835,7 +835,6 @@ export function getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker: Typ documentation = allSignatures[0].getDocumentationComment(typeChecker); tags = allSignatures[0].getJsDocTags().filter(tag => tag.name !== "deprecated"); // should only include @deprecated JSDoc tag on the first overload (#49368) } - } function writeTypeParametersOfSymbol(symbol: Symbol, enclosingDeclaration: Node | undefined) { diff --git a/tests/baselines/reference/quickInfoJsDocAlias.baseline b/tests/baselines/reference/quickInfoJsDocAlias.baseline new file mode 100644 index 00000000000..8fbd9b68665 --- /dev/null +++ b/tests/baselines/reference/quickInfoJsDocAlias.baseline @@ -0,0 +1,91 @@ +=== /b.ts === +// import { A } from "./a"; +// A() +// ^ +// | ---------------------------------------------------------------------- +// | (alias) A(): void +// | import A +// | docs - const A: T +// | ---------------------------------------------------------------------- + +[ + { + "marker": { + "fileName": "/b.ts", + "position": 26, + "name": "" + }, + "item": { + "kind": "alias", + "kindModifiers": "export,declare", + "textSpan": { + "start": 25, + "length": 1 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "alias", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "A", + "kind": "aliasName" + }, + { + "text": "(", + "kind": "punctuation" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "void", + "kind": "keyword" + }, + { + "text": "\n", + "kind": "lineBreak" + }, + { + "text": "import", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "A", + "kind": "aliasName" + } + ], + "documentation": [ + { + "text": "docs - const A: T", + "kind": "text" + } + ] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoJsDocAlias.ts b/tests/cases/fourslash/quickInfoJsDocAlias.ts new file mode 100644 index 00000000000..607f8c35a14 --- /dev/null +++ b/tests/cases/fourslash/quickInfoJsDocAlias.ts @@ -0,0 +1,15 @@ +/// + +// @filename: /a.d.ts +/////** docs - type T */ +////export type T = () => void; +/////** +//// * docs - const A: T +//// */ +////export declare const A: T; + +// @filename: /b.ts +////import { A } from "./a"; +////A/**/() + +verify.baselineQuickInfo();