From e62f960648921ccb465a583c8e8ef605e1658884 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 31 Mar 2022 01:36:47 +0300 Subject: [PATCH] fix(47733): omit JSDoc comment template suggestion on node with existing JSDoc (#47748) --- src/services/jsDoc.ts | 3 ++- .../docCommentTemplateWithExistingJSDoc.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/docCommentTemplateWithExistingJSDoc.ts diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index 43600422a5c..ca6b9cc047d 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -353,7 +353,8 @@ namespace ts.JsDoc { } const { commentOwner, parameters, hasReturn } = commentOwnerInfo; - if (commentOwner.getStart(sourceFile) < position) { + const commentOwnerJSDoc = hasJSDocNodes(commentOwner) && commentOwner.jsDoc ? lastOrUndefined(commentOwner.jsDoc) : undefined; + if (commentOwner.getStart(sourceFile) < position || commentOwnerJSDoc && commentOwnerJSDoc !== existingDocComment) { return undefined; } diff --git a/tests/cases/fourslash/docCommentTemplateWithExistingJSDoc.ts b/tests/cases/fourslash/docCommentTemplateWithExistingJSDoc.ts new file mode 100644 index 00000000000..a2dedc929ff --- /dev/null +++ b/tests/cases/fourslash/docCommentTemplateWithExistingJSDoc.ts @@ -0,0 +1,13 @@ +/// + +/////** /**/ */ +//// +/////** +//// * @param {string} a +//// * @param {string} b +//// */ +////function foo(a, b) { +//// return a + b; +////} + +verify.noDocCommentTemplateAt("");