mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 05:17:43 -05:00
findPrecedingToken: default includeJsDocComment to true (#25262)
* findPrecedingToken: default includeJsDocComment to true * Add exception for smartIndenter
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) ||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user