Skip to content

Commit c9d44ce

Browse files
author
Andy
authored
getTouchingToken: default includeJsDocComment to true (microsoft#25258)
1 parent c35cb86 commit c9d44ce

4 files changed

Lines changed: 9 additions & 13 deletions

File tree

src/services/services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,7 @@ namespace ts {
18851885

18861886
function getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[] {
18871887
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
1888-
const token = getTouchingToken(sourceFile, position, /*includeJsDocComment*/ false);
1888+
const token = getTouchingToken(sourceFile, position);
18891889
const matchKind = token.getStart(sourceFile) === position ? braceMatching.get(token.kind.toString()) : undefined;
18901890
const match = matchKind && findChildOfKind(token.parent, matchKind, sourceFile);
18911891
// We want to order the braces when we return the result.

src/services/textChanges.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ namespace ts.textChanges {
358358
// If so, we do not want to separate the node from its comment if we can.
359359
// Otherwise, add an extra new line immediately before the error span.
360360
const insertAtLineStart = isValidLocationToAddComment(sourceFile, startPosition);
361-
const token = getTouchingToken(sourceFile, insertAtLineStart ? startPosition : position, /*includeJsDocComment*/ false);
361+
const token = getTouchingToken(sourceFile, insertAtLineStart ? startPosition : position);
362362
const indent = sourceFile.text.slice(lineStartPosition, startPosition);
363363
const text = `${insertAtLineStart ? "" : this.newLineCharacter}//${commentText}${this.newLineCharacter}${indent}`;
364364
this.insertText(sourceFile, token.getStart(sourceFile), text);

src/services/utilities.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -657,33 +657,29 @@ namespace ts {
657657
* position >= start and (position < end or (position === end && token is literal or keyword or identifier))
658658
*/
659659
export function getTouchingPropertyName(sourceFile: SourceFile, position: number): Node {
660-
return getTouchingToken(sourceFile, position, /*includeJsDocComment*/ true, n => isPropertyNameLiteral(n) || isKeyword(n.kind));
660+
return getTouchingToken(sourceFile, position, n => isPropertyNameLiteral(n) || isKeyword(n.kind));
661661
}
662662

663663
/**
664664
* Returns the token if position is in [start, end).
665665
* If position === end, returns the preceding token if includeItemAtEndPosition(previousToken) === true
666666
*/
667-
export function getTouchingToken(sourceFile: SourceFile, position: number, includeJsDocComment: boolean, includePrecedingTokenAtEndPosition?: (n: Node) => boolean): Node {
668-
return getTokenAtPositionWorker(sourceFile, position, /*allowPositionInLeadingTrivia*/ false, includePrecedingTokenAtEndPosition, /*includeEndPosition*/ false, includeJsDocComment);
667+
export function getTouchingToken(sourceFile: SourceFile, position: number, includePrecedingTokenAtEndPosition?: (n: Node) => boolean): Node {
668+
return getTokenAtPositionWorker(sourceFile, position, /*allowPositionInLeadingTrivia*/ false, includePrecedingTokenAtEndPosition, /*includeEndPosition*/ false);
669669
}
670670

671671
/** Returns a token if position is in [start-of-leading-trivia, end) */
672672
export function getTokenAtPosition(sourceFile: SourceFile, position: number): Node {
673-
return getTokenAtPositionWorker(sourceFile, position, /*allowPositionInLeadingTrivia*/ true, /*includePrecedingTokenAtEndPosition*/ undefined, /*includeEndPosition*/ false, /*includeJsDocComment*/ true);
673+
return getTokenAtPositionWorker(sourceFile, position, /*allowPositionInLeadingTrivia*/ true, /*includePrecedingTokenAtEndPosition*/ undefined, /*includeEndPosition*/ false);
674674
}
675675

676676
/** Get the token whose text contains the position */
677-
function getTokenAtPositionWorker(sourceFile: SourceFile, position: number, allowPositionInLeadingTrivia: boolean, includePrecedingTokenAtEndPosition: ((n: Node) => boolean) | undefined, includeEndPosition: boolean, includeJsDocComment: boolean): Node {
677+
function getTokenAtPositionWorker(sourceFile: SourceFile, position: number, allowPositionInLeadingTrivia: boolean, includePrecedingTokenAtEndPosition: ((n: Node) => boolean) | undefined, includeEndPosition: boolean): Node {
678678
let current: Node = sourceFile;
679679
outer: while (true) {
680680
// find the child that contains 'position'
681681
for (const child of current.getChildren()) {
682-
if (!includeJsDocComment && isJSDocNode(child)) {
683-
continue;
684-
}
685-
686-
const start = allowPositionInLeadingTrivia ? child.getFullStart() : child.getStart(sourceFile, includeJsDocComment);
682+
const start = allowPositionInLeadingTrivia ? child.getFullStart() : child.getStart(sourceFile, /*includeJsDoc*/ true);
687683
if (start > position) {
688684
// If this child begins after position, then all subsequent children will as well.
689685
break;

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10742,7 +10742,7 @@ declare namespace ts {
1074210742
* Returns the token if position is in [start, end).
1074310743
* If position === end, returns the preceding token if includeItemAtEndPosition(previousToken) === true
1074410744
*/
10745-
function getTouchingToken(sourceFile: SourceFile, position: number, includeJsDocComment: boolean, includePrecedingTokenAtEndPosition?: (n: Node) => boolean): Node;
10745+
function getTouchingToken(sourceFile: SourceFile, position: number, includePrecedingTokenAtEndPosition?: (n: Node) => boolean): Node;
1074610746
/** Returns a token if position is in [start-of-leading-trivia, end) */
1074710747
function getTokenAtPosition(sourceFile: SourceFile, position: number): Node;
1074810748
/**

0 commit comments

Comments
 (0)