Skip to content

add supports of completion label list#20362

Merged
1 commit merged into
microsoft:masterfrom
Kingwl:label-completion
Dec 6, 2017
Merged

add supports of completion label list#20362
1 commit merged into
microsoft:masterfrom
Kingwl:label-completion

Conversation

@Kingwl
Copy link
Copy Markdown
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
Comment thread src/services/completions.ts Outdated
current = current.parent;
}

for (const stmt of statements) {
Copy link
Copy Markdown
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.

Comment thread src/services/utilities.ts Outdated
return false;
}

export function isBreakOrContinue(kind: SyntaxKind) {
Copy link
Copy Markdown
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

Comment thread 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));
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

Comment thread src/services/completions.ts Outdated
}

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

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.

Comment thread src/services/completions.ts Outdated

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

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?

Comment thread src/services/completions.ts Outdated
}

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

Choose a reason for hiding this comment

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

Unnecessary type annotation

Comment thread src/services/completions.ts Outdated
return undefined;
}

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

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.

Comment thread src/services/completions.ts Outdated
break;
}
if (isLabeledStatement(current)) {
const name = current.label.escapedText as string;
Copy link
Copy Markdown

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.

Comment thread src/services/utilities.ts Outdated
return false;
}

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

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.

Comment thread src/services/utilities.ts Outdated

export function isInBreakOrContinue(sourceFile: SourceFile, position: number): boolean {
const contextToken = findPrecedingToken(position, sourceFile);
return contextToken && contextToken.parent &&
Copy link
Copy Markdown

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
Copy Markdown
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.

Comment thread src/services/completions.ts Outdated
}

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

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
Copy Markdown
Contributor Author

Kingwl commented Dec 6, 2017

ping @Andy-MS updated

@ghost
Copy link
Copy Markdown

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