Skip to content

Minor cleanup for label completions #20502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Dec 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/services/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ namespace ts.Completions {
}

const contextToken = findPrecedingToken(position, sourceFile);
if (isInBreakOrContinue(contextToken)) {
return getLabelCompletionAtPosition(contextToken);
if (contextToken && isBreakOrContinueStatement(contextToken.parent)
&& (contextToken.kind === SyntaxKind.BreakKeyword || contextToken.kind === SyntaxKind.ContinueKeyword || contextToken.kind === SyntaxKind.Identifier)) {
return getLabelCompletionAtPosition(contextToken.parent);
}

const completionData = getCompletionData(typeChecker, log, sourceFile, position, allSourceFiles, options, compilerOptions.target);
Expand Down Expand Up @@ -228,13 +229,8 @@ namespace ts.Completions {
return uniques;
}

function isInBreakOrContinue(contextToken: Node): boolean {
return contextToken && isBreakOrContinueStatement(contextToken.parent) &&
(contextToken.kind === SyntaxKind.BreakKeyword || contextToken.kind === SyntaxKind.ContinueKeyword || contextToken.kind === SyntaxKind.Identifier);
}

function getLabelCompletionAtPosition(contextToken: Node): CompletionInfo | undefined {
const entries = getLabelStatementCompletions(contextToken.parent);
function getLabelCompletionAtPosition(node: BreakOrContinueStatement): CompletionInfo | undefined {
const entries = getLabelStatementCompletions(node);
if (entries.length) {
return { isGlobalCompletion: false, isMemberCompletion: false, isNewIdentifierLocation: false, entries };
}
Expand Down