Skip to content

Commit 7b76416

Browse files
Armando AguirreArmando Aguirresandersn
authored
Fixed closing JSDoc when adding multiple blocks (#49888)
* Fixed closing JSDoc when adding multiple blocks * Fixed linting errors * Refactored to use `some` Co-authored-by: Nathan Shively-Sanders <[email protected]> * Removed empty lines Co-authored-by: Armando Aguirre <[email protected]> Co-authored-by: Nathan Shively-Sanders <[email protected]>
1 parent 5d2e62a commit 7b76416

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/services/jsDoc.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,12 @@ namespace ts.JsDoc {
357357
}
358358

359359
const { commentOwner, parameters, hasReturn } = commentOwnerInfo;
360-
const commentOwnerJSDoc = hasJSDocNodes(commentOwner) && commentOwner.jsDoc ? lastOrUndefined(commentOwner.jsDoc) : undefined;
361-
if (commentOwner.getStart(sourceFile) < position || commentOwnerJSDoc && commentOwnerJSDoc !== existingDocComment) {
360+
const commentOwnerJsDoc = hasJSDocNodes(commentOwner) && commentOwner.jsDoc ? commentOwner.jsDoc : undefined;
361+
const lastJsDoc = lastOrUndefined(commentOwnerJsDoc);
362+
if (commentOwner.getStart(sourceFile) < position
363+
|| lastJsDoc
364+
&& existingDocComment
365+
&& lastJsDoc !== existingDocComment) {
362366
return undefined;
363367
}
364368

@@ -378,7 +382,11 @@ namespace ts.JsDoc {
378382
// * if the caret was directly in front of the object, then we add an extra line and indentation.
379383
const openComment = "/**";
380384
const closeComment = " */";
381-
if (tags) {
385+
386+
// If any of the existing jsDoc has tags, ignore adding new ones.
387+
const hasTag = (commentOwnerJsDoc || []).some(jsDoc => !!jsDoc.tags);
388+
389+
if (tags && !hasTag) {
382390
const preamble = openComment + newLine + indentationStr + " * ";
383391
const endLine = tokenStart === position ? newLine + indentationStr : "";
384392
const result = preamble + newLine + tags + indentationStr + closeComment + endLine;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
/////** */
4+
/////*/**/
5+
////function foo() {}
6+
7+
verify.docCommentTemplateAt("", 3, "/** */");
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
/////** */
4+
/////**
5+
//// *
6+
//// * @param p
7+
//// */
8+
/////** */
9+
/////*/**/
10+
////function foo(p) {}
11+
12+
verify.docCommentTemplateAt("", 3, "/** */");

0 commit comments

Comments
 (0)