Support completions inside JSDoc before EndOfFileToken (#25568)

This commit is contained in:
Andy
2018-09-05 11:34:27 -07:00
committed by GitHub
parent 62d8b85f1d
commit 1eb3082387
4 changed files with 32 additions and 22 deletions

View File

@@ -755,7 +755,7 @@ namespace ts {
return result;
function find(n: Node): Node | undefined {
if (isNonWhitespaceToken(n)) {
if (isNonWhitespaceToken(n) && n.kind !== SyntaxKind.EndOfFileToken) {
return n;
}
@@ -786,16 +786,14 @@ namespace ts {
}
}
Debug.assert(startNode !== undefined || n.kind === SyntaxKind.SourceFile || isJSDocCommentContainingNode(n));
Debug.assert(startNode !== undefined || n.kind === SyntaxKind.SourceFile || n.kind === SyntaxKind.EndOfFileToken || isJSDocCommentContainingNode(n));
// Here we know that none of child token nodes embrace the position,
// the only known case is when position is at the end of the file.
// Try to find the rightmost token in the file without filtering.
// Namely we are skipping the check: 'position < node.end'
if (children.length) {
const candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
return candidate && findRightmostToken(candidate, sourceFile);
}
const candidate = findRightmostChildNodeWithTokens(children, /*exclusiveStartPosition*/ children.length, sourceFile);
return candidate && findRightmostToken(candidate, sourceFile);
}
}
@@ -1048,7 +1046,7 @@ namespace ts {
function nodeHasTokens(n: Node, sourceFile: SourceFileLike): boolean {
// If we have a token or node that has a non-zero width, it must have tokens.
// Note: getWidth() does not take trivia into account.
return n.getWidth(sourceFile) !== 0;
return n.kind === SyntaxKind.EndOfFileToken ? !!(n as EndOfFileToken).jsDoc : n.getWidth(sourceFile) !== 0;
}
export function getNodeModifiers(node: Node): string {