From bd9daf38e17da7302e718e529417148e3255a331 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 6 Feb 2020 09:19:58 -0800 Subject: [PATCH 1/2] Support property declarations in jsdoc template generation --- src/services/jsDoc.ts | 6 +++- .../docCommentTemplateClassDeclProperty01.ts | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/docCommentTemplateClassDeclProperty01.ts diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index 56e0a0ae50ed6..a837d7d353850 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -251,7 +251,6 @@ namespace ts.JsDoc { * @param position The (character-indexed) position in the file where the check should * be performed. */ - export function getDocCommentTemplateAtPosition(newLine: string, sourceFile: SourceFile, position: number): TextInsertion | undefined { const tokenAtPos = getTokenAtPosition(sourceFile, position); const existingDocComment = findAncestor(tokenAtPos, isJSDoc); @@ -370,6 +369,11 @@ namespace ts.JsDoc { const parameters = isFunctionLike(be.right) ? be.right.parameters : emptyArray; return { commentOwner, parameters }; } + case SyntaxKind.PropertyDeclaration: + const init = (commentOwner as PropertyDeclaration).initializer; + if (init && (isFunctionExpression(init) || isArrowFunction(init))) { + return { commentOwner, parameters: init.parameters }; + } } } diff --git a/tests/cases/fourslash/docCommentTemplateClassDeclProperty01.ts b/tests/cases/fourslash/docCommentTemplateClassDeclProperty01.ts new file mode 100644 index 0000000000000..85dcd6e1a8713 --- /dev/null +++ b/tests/cases/fourslash/docCommentTemplateClassDeclProperty01.ts @@ -0,0 +1,28 @@ +/// + +const singleLineOffset = 3; +const multiLineOffset = 12; + + +////class C { +//// /** /*0*/ */ +//// foo = (p0) => { +//// return p0; +//// }; +//// /*1*/ +//// bar = (p1) => { +//// return p1; +//// } +////} + +verify.docCommentTemplateAt("0", multiLineOffset, + `/** + * + * @param p0 + */`); +verify.docCommentTemplateAt("1", multiLineOffset, + `/** + * + * @param p1 + */`); + From e1cc9f2a070a45885ffe86475649cb9f905bd01f Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 6 Feb 2020 14:18:49 -0800 Subject: [PATCH 2/2] fix lint and add test --- src/services/jsDoc.ts | 2 +- .../docCommentTemplateClassDeclProperty01.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index a837d7d353850..995561c016b7d 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -372,7 +372,7 @@ namespace ts.JsDoc { case SyntaxKind.PropertyDeclaration: const init = (commentOwner as PropertyDeclaration).initializer; if (init && (isFunctionExpression(init) || isArrowFunction(init))) { - return { commentOwner, parameters: init.parameters }; + return { commentOwner, parameters: init.parameters }; } } } diff --git a/tests/cases/fourslash/docCommentTemplateClassDeclProperty01.ts b/tests/cases/fourslash/docCommentTemplateClassDeclProperty01.ts index 85dcd6e1a8713..ee235f34cec3b 100644 --- a/tests/cases/fourslash/docCommentTemplateClassDeclProperty01.ts +++ b/tests/cases/fourslash/docCommentTemplateClassDeclProperty01.ts @@ -13,6 +13,10 @@ const multiLineOffset = 12; //// bar = (p1) => { //// return p1; //// } +//// /*2*/ +//// baz = function (p2, p3) { +//// return p2; +//// } ////} verify.docCommentTemplateAt("0", multiLineOffset, @@ -25,4 +29,11 @@ verify.docCommentTemplateAt("1", multiLineOffset, * * @param p1 */`); +verify.docCommentTemplateAt("2", multiLineOffset, + `/** + * + * @param p2 + * @param p3 + */`); +