File tree Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff line change 1+ /// <reference path='fourslash.ts' />
2+
3+ /////** */
4+ /////*/**/
5+ ////function foo() {}
6+
7+ verify . docCommentTemplateAt ( "" , 3 , "/** */" ) ;
Original file line number Diff line number Diff line change 1+ /// <reference path='fourslash.ts' />
2+
3+ /////** */
4+ /////**
5+ //// *
6+ //// * @param p
7+ //// */
8+ /////** */
9+ /////*/**/
10+ ////function foo(p) {}
11+
12+ verify . docCommentTemplateAt ( "" , 3 , "/** */" ) ;
You can’t perform that action at this time.
0 commit comments