add supports of completion label list#20362
Conversation
10c3a7c to
117aa03
Compare
| current = current.parent; | ||
| } | ||
|
|
||
| for (const stmt of statements) { |
There was a problem hiding this comment.
i would combine these two loops.
| return false; | ||
| } | ||
|
|
||
| export function isBreakOrContinue(kind: SyntaxKind) { |
There was a problem hiding this comment.
we already have isBreakOrContinueStatement
|
|
||
| export function isInBreakOrContinue(sourceFile: SourceFile, position: number): boolean { | ||
| const contextToken = findPrecedingToken(position, sourceFile); | ||
| return contextToken && (isBreakOrContinue(contextToken.kind) || contextToken.parent && isIdentifier(contextToken) && isBreakOrContinueStatement(contextToken.parent)); |
There was a problem hiding this comment.
we already do this in getCompletionData, consider moving the check for isLabeledCompletion to that function.
|
@Andy-MS can you please review. |
ee9998e to
c424e67
Compare
|
ping @mhegazy
But I still prefer to keep completion Label alone instead of putting it in |
c424e67 to
429ba67
Compare
| } | ||
|
|
||
| function getLabelCompletionAtPosition(sourceFile: SourceFile, position: number): CompletionInfo | undefined { | ||
| const contextToken: Node = findPrecedingToken(position, sourceFile); |
|
|
||
| function getLabelCompletionAtPosition(sourceFile: SourceFile, position: number): CompletionInfo | undefined { | ||
| const contextToken: Node = findPrecedingToken(position, sourceFile); | ||
| if (!contextToken || !contextToken.parent || |
There was a problem hiding this comment.
You just tested for this in isInBreakOrContinue, right?
| } | ||
|
|
||
| function addLabelStatementCompletions(node: Node, entries: CompletionEntry[], uniques = createMap<true>()): void { | ||
| let current: Node = node; |
| return undefined; | ||
| } | ||
|
|
||
| function addLabelStatementCompletions(node: Node, entries: CompletionEntry[], uniques = createMap<true>()): void { |
There was a problem hiding this comment.
This really only depends on the node. You can remove the uniques parameter and just use const uniques = createMap<true>, and remove the entries parameter and just return an array.
| break; | ||
| } | ||
| if (isLabeledStatement(current)) { | ||
| const name = current.label.escapedText as string; |
| return false; | ||
| } | ||
|
|
||
| export function isInBreakOrContinue(sourceFile: SourceFile, position: number): boolean { |
There was a problem hiding this comment.
I would just move this to completions.ts since it's unlikely to be needed outside of a completion context.
|
|
||
| export function isInBreakOrContinue(sourceFile: SourceFile, position: number): boolean { | ||
| const contextToken = findPrecedingToken(position, sourceFile); | ||
| return contextToken && contextToken.parent && |
There was a problem hiding this comment.
If the kind matches, the parent will exist (since it's not a SourceFile), so no need to test for && contextToken.parent.
429ba67 to
f14448b
Compare
|
ping @Andy-MS |
f14448b to
b4ac6f5
Compare
| } | ||
|
|
||
| function getLabelCompletionAtPosition(sourceFile: SourceFile, position: number): CompletionInfo | undefined { | ||
| const contextToken = findPrecedingToken(position, sourceFile); |
There was a problem hiding this comment.
This was just computed in isBreakOrContinue, move this outside so it's only computed once.
b4ac6f5 to
2d9e9a2
Compare
|
ping @Andy-MS updated |
|
Thanks! |
Fixes #4960