Skip to content

Return string completions for indexed access types#20941

Merged
DanielRosenwasser merged 1 commit intomicrosoft:masterfrom
mariusschulz:stringCompletionsForIndexedAccessTypes
Jan 7, 2018
Merged

Return string completions for indexed access types#20941
DanielRosenwasser merged 1 commit intomicrosoft:masterfrom
mariusschulz:stringCompletionsForIndexedAccessTypes

Conversation

@mariusschulz
Copy link
Copy Markdown
Contributor

Fixes #20938

This PR provides string literal completions within indexed access types.

Does this look good to you, @DanielRosenwasser? Let me know if you need me to add anything else.

Copy link
Copy Markdown
Member

@DanielRosenwasser DanielRosenwasser left a comment

Choose a reason for hiding this comment

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

Looks good! Though I would also rename the test completionForStringLiteral14.ts to completionForStringLiteralInIndexedAccess01.ts

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

function getStringLiteralCompletionsFromIndexedAccess(node: IndexedAccessTypeNode, typeChecker: TypeChecker, target: ScriptTarget, log: Log): CompletionInfo | undefined {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since this is mostly the same as getStringLiteralCompletionEntriesFromElementAccess, I would combine them into getStringLiteralCompletionEntriesFromElementAccessOrIndexedAccess, and call them with the appropriate type and stringLiteralNode.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That definitely makes sense. Would you be okay with stringLiteralNode: Node as a parameter, or would you prefer stringLiteralNode: StringLiteral | NoSubstitutionTemplateLiteral?

@mariusschulz mariusschulz force-pushed the stringCompletionsForIndexedAccessTypes branch from 613f15d to 73d4461 Compare December 30, 2017 11:19
@mariusschulz
Copy link
Copy Markdown
Contributor Author

@DanielRosenwasser I've updated the PR based on your feedback. Instead of doing manual .kind comparisons, I'm now calling the type guard functions isStringLiteral(node) and isNoSubstitutionTemplateLiteral(node) so we can have TypeScript infer the type StringLiteral | NoSubstitutionTemplateLiteral for node. Does that work for you?

@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented Jan 4, 2018

@mariusschulz can you please refresh the PR and address the merge conflicts

@mariusschulz mariusschulz force-pushed the stringCompletionsForIndexedAccessTypes branch from 73d4461 to be0c57d Compare January 5, 2018 17:11
@mariusschulz mariusschulz force-pushed the stringCompletionsForIndexedAccessTypes branch from be0c57d to 25c5e57 Compare January 5, 2018 17:14
@mariusschulz
Copy link
Copy Markdown
Contributor Author

@mhegazy Sure, done!

@DanielRosenwasser DanielRosenwasser merged commit 1041f09 into microsoft:master Jan 7, 2018
@DanielRosenwasser
Copy link
Copy Markdown
Member

Thanks Marius!

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
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.

3 participants