diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index e85246e9eb5b9..257531c14e8d9 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -357,8 +357,12 @@ namespace ts.JsDoc { } const { commentOwner, parameters, hasReturn } = commentOwnerInfo; - const commentOwnerJSDoc = hasJSDocNodes(commentOwner) && commentOwner.jsDoc ? lastOrUndefined(commentOwner.jsDoc) : undefined; - if (commentOwner.getStart(sourceFile) < position || commentOwnerJSDoc && commentOwnerJSDoc !== existingDocComment) { + const commentOwnerJsDoc = hasJSDocNodes(commentOwner) && commentOwner.jsDoc ? commentOwner.jsDoc : undefined; + const lastJsDoc = lastOrUndefined(commentOwnerJsDoc); + if (commentOwner.getStart(sourceFile) < position + || lastJsDoc + && existingDocComment + && lastJsDoc !== existingDocComment) { return undefined; } @@ -378,7 +382,11 @@ namespace ts.JsDoc { // * if the caret was directly in front of the object, then we add an extra line and indentation. const openComment = "/**"; const closeComment = " */"; - if (tags) { + + // If any of the existing jsDoc has tags, ignore adding new ones. + const hasTag = (commentOwnerJsDoc || []).some(jsDoc => !!jsDoc.tags); + + if (tags && !hasTag) { const preamble = openComment + newLine + indentationStr + " * "; const endLine = tokenStart === position ? newLine + indentationStr : ""; const result = preamble + newLine + tags + indentationStr + closeComment + endLine; diff --git a/tests/cases/fourslash/docCommentTemplateWithMultipleJSDoc.ts b/tests/cases/fourslash/docCommentTemplateWithMultipleJSDoc.ts new file mode 100644 index 0000000000000..f1b2c3fad3cab --- /dev/null +++ b/tests/cases/fourslash/docCommentTemplateWithMultipleJSDoc.ts @@ -0,0 +1,7 @@ +/// + +/////** */ +/////*/**/ +////function foo() {} + +verify.docCommentTemplateAt("", 3, "/** */"); diff --git a/tests/cases/fourslash/docCommentTemplateWithMultipleJSDocAndParameters.ts b/tests/cases/fourslash/docCommentTemplateWithMultipleJSDocAndParameters.ts new file mode 100644 index 0000000000000..add01b90006cf --- /dev/null +++ b/tests/cases/fourslash/docCommentTemplateWithMultipleJSDocAndParameters.ts @@ -0,0 +1,12 @@ +/// + +/////** */ +/////** +//// * +//// * @param p +//// */ +/////** */ +/////*/**/ +////function foo(p) {} + +verify.docCommentTemplateAt("", 3, "/** */");