Skip to content

Commit 1cb691f

Browse files
author
Andy
authored
findPrecedingToken: default includeJsDocComment to true (microsoft#25262)
* findPrecedingToken: default includeJsDocComment to true * Add exception for smartIndenter
1 parent c9d44ce commit 1cb691f

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/services/completions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ namespace ts.Completions {
871871
}
872872

873873
start = timestamp();
874-
const previousToken = findPrecedingToken(position, sourceFile, /*startNode*/ undefined, insideJsDocTagTypeExpression)!; // TODO: GH#18217
874+
const previousToken = findPrecedingToken(position, sourceFile, /*startNode*/ undefined)!; // TODO: GH#18217
875875
log("getCompletionData: Get previous token 1: " + (timestamp() - start));
876876

877877
// The decision to provide completion depends on the contextToken, which is determined through the previousToken.
@@ -882,7 +882,7 @@ namespace ts.Completions {
882882
// Skip this partial identifier and adjust the contextToken to the token that precedes it.
883883
if (contextToken && position <= contextToken.end && (isIdentifier(contextToken) || isKeyword(contextToken.kind))) {
884884
const start = timestamp();
885-
contextToken = findPrecedingToken(contextToken.getFullStart(), sourceFile, /*startNode*/ undefined, insideJsDocTagTypeExpression)!; // TODO: GH#18217
885+
contextToken = findPrecedingToken(contextToken.getFullStart(), sourceFile, /*startNode*/ undefined)!; // TODO: GH#18217
886886
log("getCompletionData: Get previous token 2: " + (timestamp() - start));
887887
}
888888

src/services/formatting/smartIndenter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace ts.formatting {
3232
return 0;
3333
}
3434

35-
const precedingToken = findPrecedingToken(position, sourceFile);
35+
const precedingToken = findPrecedingToken(position, sourceFile, /*startNode*/ undefined, /*excludeJsdoc*/ true);
3636

3737
const enclosingCommentRange = getRangeOfEnclosingComment(sourceFile, position, /*onlyMultiLine*/ true, precedingToken || null); // tslint:disable-line:no-null-keyword
3838
if (enclosingCommentRange) {

src/services/utilities.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ namespace ts {
751751
* Finds the rightmost token satisfying `token.end <= position`,
752752
* excluding `JsxText` tokens containing only whitespace.
753753
*/
754-
export function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node, includeJsDoc?: boolean): Node | undefined {
754+
export function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node, excludeJsdoc?: boolean): Node | undefined {
755755
const result = find(startNode || sourceFile);
756756
Debug.assert(!(result && isWhiteSpaceOnlyJsxText(result)));
757757
return result;
@@ -770,7 +770,7 @@ namespace ts {
770770
// we need to find the last token in a previous child.
771771
// 2) `position` is within the same span: we recurse on `child`.
772772
if (position < child.end) {
773-
const start = child.getStart(sourceFile, includeJsDoc);
773+
const start = child.getStart(sourceFile, /*includeJsDoc*/ !excludeJsdoc);
774774
const lookInPreviousChild =
775775
(start >= position) || // cursor in the leading trivia
776776
!nodeHasTokens(child, sourceFile) ||

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10759,7 +10759,7 @@ declare namespace ts {
1075910759
* Finds the rightmost token satisfying `token.end <= position`,
1076010760
* excluding `JsxText` tokens containing only whitespace.
1076110761
*/
10762-
function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node, includeJsDoc?: boolean): Node | undefined;
10762+
function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node, excludeJsdoc?: boolean): Node | undefined;
1076310763
function isInString(sourceFile: SourceFile, position: number, previousToken?: Node | undefined): boolean;
1076410764
/**
1076510765
* returns true if the position is in between the open and close elements of an JSX expression.

0 commit comments

Comments
 (0)