Skip to content

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

Merged
1 commit merged into from
Dec 6, 2017
Merged

Conversation

Kingwl
Copy link
Contributor

@Kingwl Kingwl commented Nov 30, 2017

Fixes #4960

@Kingwl Kingwl changed the title add supports of completion label list WIP: add supports of completion label list Nov 30, 2017
@Kingwl Kingwl changed the title WIP: add supports of completion label list add supports of completion label list Nov 30, 2017
current = current.parent;
}

for (const stmt of statements) {
Copy link
Contributor

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.

@@ -857,6 +857,15 @@ namespace ts {
return false;
}

export function isBreakOrContinue(kind: SyntaxKind) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Contributor

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.

@mhegazy mhegazy requested a review from a user December 2, 2017 01:35
@mhegazy
Copy link
Contributor

mhegazy commented Dec 2, 2017

@Andy-MS can you please review.

@Kingwl Kingwl force-pushed the label-completion branch 2 times, most recently from ee9998e to c424e67 Compare December 4, 2017 02:21
@Kingwl
Copy link
Contributor Author

Kingwl commented Dec 4, 2017

ping @mhegazy
thanks for you review
I did the following after your review

  1. merged two loops
  2. remove the isBreakOrContrinue
  3. simplify the type of judgment

But I still prefer to keep completion Label alone instead of putting it in GetCompletionData.
the GetCompletionData return the interface CompletionData with the symbols field.
but the label filed of labelStmt is Identity
so have i miss something?

@@ -223,6 +227,21 @@ namespace ts.Completions {
return uniques;
}

function getLabelCompletionAtPosition(sourceFile: SourceFile, position: number): CompletionInfo | undefined {
const contextToken: Node = findPrecedingToken(position, sourceFile);
Copy link

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.

@@ -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 ||
Copy link

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?

@@ -358,6 +377,28 @@ namespace ts.Completions {
return undefined;
}

function addLabelStatementCompletions(node: Node, entries: CompletionEntry[], uniques = createMap<true>()): void {
let current: Node = node;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary type annotation

@@ -358,6 +377,28 @@ namespace ts.Completions {
return undefined;
}

function addLabelStatementCompletions(node: Node, entries: CompletionEntry[], uniques = createMap<true>()): void {
Copy link

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.

break;
}
if (isLabeledStatement(current)) {
const name = current.label.escapedText as string;
Copy link

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.

@@ -857,6 +857,13 @@ namespace ts {
return false;
}

export function isInBreakOrContinue(sourceFile: SourceFile, position: number): boolean {
Copy link

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.

@@ -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 &&
Copy link

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.

@mhegazy mhegazy requested a review from a user December 4, 2017 19:05
@Kingwl
Copy link
Contributor Author

Kingwl commented Dec 5, 2017

ping @Andy-MS
thanks for your review
i remove the Unnecessary parameter, type annotation, cast and type test
but i'm not sure what means Just pass in the token.

}

function getLabelCompletionAtPosition(sourceFile: SourceFile, position: number): CompletionInfo | undefined {
const contextToken = findPrecedingToken(position, sourceFile);
Copy link

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.

@Kingwl
Copy link
Contributor Author

Kingwl commented Dec 6, 2017

ping @Andy-MS updated

@ghost
Copy link

ghost commented Dec 6, 2017

Thanks!

@ghost ghost merged commit ae25d09 into microsoft:master Dec 6, 2017
@ghost ghost mentioned this pull request Dec 6, 2017
@Kingwl Kingwl deleted the label-completion branch December 6, 2017 15:30
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants