findPrecedingToken: default includeJsDocComment to true (#25262)

* findPrecedingToken: default includeJsDocComment to true

* Add exception for smartIndenter
This commit is contained in:
Andy
2018-06-27 12:14:41 -07:00
committed by GitHub
parent c9d44ce395
commit 1cb691f52d
4 changed files with 6 additions and 6 deletions

View File

@@ -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));
}

View File

@@ -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) {

View File

@@ -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) ||