From 4af8333a4e371eb8069c2e1534346ddc207bd3f5 Mon Sep 17 00:00:00 2001 From: Zzzen <843968788@qq.com> Date: Thu, 17 Jun 2021 05:46:49 +0800 Subject: [PATCH] support JSDoc comments inherited for parameter properties (#44329) * support JSDoc comments inherited for parameter properties * Update formats Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> --- src/services/services.ts | 6 +- .../quickInfoOnParameterProperties.baseline | 128 ++++++++++++++++++ .../quickInfoOnParameterProperties.ts | 29 ++++ 3 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/quickInfoOnParameterProperties.baseline create mode 100644 tests/cases/fourslash/quickInfoOnParameterProperties.ts diff --git a/src/services/services.ts b/src/services/services.ts index afe43e32a79..0d14cda15da 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -591,7 +591,11 @@ namespace ts { } function findBaseOfDeclaration(checker: TypeChecker, declaration: Declaration, cb: (symbol: Symbol) => T[] | undefined): T[] | undefined { - return firstDefined(declaration.parent ? getAllSuperTypeNodes(declaration.parent) : emptyArray, superTypeNode => { + const classOrInterfaceDeclaration = declaration.parent?.kind === SyntaxKind.Constructor ? declaration.parent.parent : declaration.parent; + if (!classOrInterfaceDeclaration) { + return; + } + return firstDefined(getAllSuperTypeNodes(classOrInterfaceDeclaration), superTypeNode => { const symbol = checker.getPropertyOfType(checker.getTypeAtLocation(superTypeNode), declaration.symbol.name); return symbol ? cb(symbol) : undefined; }); diff --git a/tests/baselines/reference/quickInfoOnParameterProperties.baseline b/tests/baselines/reference/quickInfoOnParameterProperties.baseline new file mode 100644 index 00000000000..ab4f05c5f47 --- /dev/null +++ b/tests/baselines/reference/quickInfoOnParameterProperties.baseline @@ -0,0 +1,128 @@ +[ + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoOnParameterProperties.ts", + "position": 226, + "name": "1" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "public", + "textSpan": { + "start": 224, + "length": 4 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Foo", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "name", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [ + { + "text": "this is the name of blabla \n- use blabla", + "kind": "text" + } + ] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoOnParameterProperties.ts", + "position": 347, + "name": "2" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "public", + "textSpan": { + "start": 345, + "length": 4 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Foo2", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "name", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [ + { + "text": "this is the name of blabla \n- use blabla", + "kind": "text" + } + ] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoOnParameterProperties.ts b/tests/cases/fourslash/quickInfoOnParameterProperties.ts new file mode 100644 index 00000000000..7f3552a5024 --- /dev/null +++ b/tests/cases/fourslash/quickInfoOnParameterProperties.ts @@ -0,0 +1,29 @@ +/// + +////interface IFoo { +//// /** this is the name of blabla +//// * - use blabla +//// * @example blabla +//// */ +//// name?: string; +////} +//// +////// test1 should work +////class Foo implements IFoo { +//// //public name: string = ''; +//// constructor( +//// public na/*1*/me: string, // documentation should leech and work ! +//// ) { +//// } +////} +//// +////// test2 work +////class Foo2 implements IFoo { +//// public na/*2*/me: string = ''; // documentation leeched and work ! +//// constructor( +//// //public name: string, +//// ) { +//// } +////} + +verify.baselineQuickInfo()