-
Notifications
You must be signed in to change notification settings - Fork 12.8k
add supports of completion label list #20362
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
Conversation
10c3a7c
to
117aa03
Compare
src/services/completions.ts
Outdated
current = current.parent; | ||
} | ||
|
||
for (const stmt of statements) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would combine these two loops.
src/services/utilities.ts
Outdated
@@ -857,6 +857,15 @@ namespace ts { | |||
return false; | |||
} | |||
|
|||
export function isBreakOrContinue(kind: SyntaxKind) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already have isBreakOrContinueStatement
src/services/utilities.ts
Outdated
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
src/services/completions.ts
Outdated
@@ -223,6 +227,21 @@ namespace ts.Completions { | |||
return uniques; | |||
} | |||
|
|||
function getLabelCompletionAtPosition(sourceFile: SourceFile, position: number): CompletionInfo | undefined { | |||
const contextToken: Node = findPrecedingToken(position, sourceFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pass in the token.
src/services/completions.ts
Outdated
@@ -223,6 +227,21 @@ namespace ts.Completions { | |||
return uniques; | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You just tested for this in isInBreakOrContinue
, right?
src/services/completions.ts
Outdated
@@ -358,6 +377,28 @@ namespace ts.Completions { | |||
return undefined; | |||
} | |||
|
|||
function addLabelStatementCompletions(node: Node, entries: CompletionEntry[], uniques = createMap<true>()): void { | |||
let current: Node = node; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary type annotation
src/services/completions.ts
Outdated
@@ -358,6 +377,28 @@ namespace ts.Completions { | |||
return undefined; | |||
} | |||
|
|||
function addLabelStatementCompletions(node: Node, entries: CompletionEntry[], uniques = createMap<true>()): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/services/completions.ts
Outdated
break; | ||
} | ||
if (isLabeledStatement(current)) { | ||
const name = current.label.escapedText as string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use .text
to avoid the cast.
src/services/utilities.ts
Outdated
@@ -857,6 +857,13 @@ namespace ts { | |||
return false; | |||
} | |||
|
|||
export function isInBreakOrContinue(sourceFile: SourceFile, position: number): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just move this to completions.ts
since it's unlikely to be needed outside of a completion context.
src/services/utilities.ts
Outdated
@@ -857,6 +857,13 @@ namespace ts { | |||
return false; | |||
} | |||
|
|||
export function isInBreakOrContinue(sourceFile: SourceFile, position: number): boolean { | |||
const contextToken = findPrecedingToken(position, sourceFile); | |||
return contextToken && contextToken.parent && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
src/services/completions.ts
Outdated
} | ||
|
||
function getLabelCompletionAtPosition(sourceFile: SourceFile, position: number): CompletionInfo | undefined { | ||
const contextToken = findPrecedingToken(position, sourceFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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