From 1cb691f52dda0a799a4ca95c1fb8f516dc28d6cc Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 27 Jun 2018 12:14:41 -0700 Subject: [PATCH] findPrecedingToken: default includeJsDocComment to true (#25262) * findPrecedingToken: default includeJsDocComment to true * Add exception for smartIndenter --- src/services/completions.ts | 4 ++-- src/services/formatting/smartIndenter.ts | 2 +- src/services/utilities.ts | 4 ++-- tests/baselines/reference/api/tsserverlibrary.d.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/services/completions.ts b/src/services/completions.ts index 4160ac80369..535f6f4f745 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -871,7 +871,7 @@ namespace ts.Completions { } start = timestamp(); - const previousToken = findPrecedingToken(position, sourceFile, /*startNode*/ undefined, insideJsDocTagTypeExpression)!; // TODO: GH#18217 + const previousToken = findPrecedingToken(position, sourceFile, /*startNode*/ undefined)!; // TODO: GH#18217 log("getCompletionData: Get previous token 1: " + (timestamp() - start)); // The decision to provide completion depends on the contextToken, which is determined through the previousToken. @@ -882,7 +882,7 @@ namespace ts.Completions { // Skip this partial identifier and adjust the contextToken to the token that precedes it. if (contextToken && position <= contextToken.end && (isIdentifier(contextToken) || isKeyword(contextToken.kind))) { const start = timestamp(); - contextToken = findPrecedingToken(contextToken.getFullStart(), sourceFile, /*startNode*/ undefined, insideJsDocTagTypeExpression)!; // TODO: GH#18217 + contextToken = findPrecedingToken(contextToken.getFullStart(), sourceFile, /*startNode*/ undefined)!; // TODO: GH#18217 log("getCompletionData: Get previous token 2: " + (timestamp() - start)); } diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 8602347244f..a03154df642 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -32,7 +32,7 @@ namespace ts.formatting { return 0; } - const precedingToken = findPrecedingToken(position, sourceFile); + const precedingToken = findPrecedingToken(position, sourceFile, /*startNode*/ undefined, /*excludeJsdoc*/ true); const enclosingCommentRange = getRangeOfEnclosingComment(sourceFile, position, /*onlyMultiLine*/ true, precedingToken || null); // tslint:disable-line:no-null-keyword if (enclosingCommentRange) { diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 75d2c157b14..33f77758abd 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -751,7 +751,7 @@ namespace ts { * Finds the rightmost token satisfying `token.end <= position`, * excluding `JsxText` tokens containing only whitespace. */ - export function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node, includeJsDoc?: boolean): Node | undefined { + export function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node, excludeJsdoc?: boolean): Node | undefined { const result = find(startNode || sourceFile); Debug.assert(!(result && isWhiteSpaceOnlyJsxText(result))); return result; @@ -770,7 +770,7 @@ namespace ts { // we need to find the last token in a previous child. // 2) `position` is within the same span: we recurse on `child`. if (position < child.end) { - const start = child.getStart(sourceFile, includeJsDoc); + const start = child.getStart(sourceFile, /*includeJsDoc*/ !excludeJsdoc); const lookInPreviousChild = (start >= position) || // cursor in the leading trivia !nodeHasTokens(child, sourceFile) || diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 5438ceb0722..435ea20bc2f 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -10759,7 +10759,7 @@ declare namespace ts { * Finds the rightmost token satisfying `token.end <= position`, * excluding `JsxText` tokens containing only whitespace. */ - function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node, includeJsDoc?: boolean): Node | undefined; + function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node, excludeJsdoc?: boolean): Node | undefined; function isInString(sourceFile: SourceFile, position: number, previousToken?: Node | undefined): boolean; /** * returns true if the position is in between the open and close elements of an JSX expression.