Skip to content

Allow quoted names in completions #18162

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
3 commits merged into from
Sep 6, 2017
Merged

Allow quoted names in completions #18162

3 commits merged into from
Sep 6, 2017

Conversation

ghost
Copy link

@ghost ghost commented Aug 30, 2017

Fixes #17040
This was a pretty simple change as I just had to change the code that had previously been returning undefined on any quoted name.
There may be objections to this as there were to #16864, so CC @rbuckton @weswigham

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

I don't actually have any objections to this, conceptually, since we've said that we wanted to offer completions for strings of all kinds for awhile. I do have a remark on the regex being used for number matching, though.

}

return name;
}

function isNumericLiteralText(name: string): boolean {
return /^-?\d+(\.\d+)?(e\d+)?$/.test(name);
Copy link
Member

Choose a reason for hiding this comment

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

There are contexts like property names:

            const foob = {
                -0() {
                    return 1;
                }
            };

where a leading minus would never be allowed (only an identifier, string literal, or number) - I don't think this should include the check for -??

Copy link
Member

Choose a reason for hiding this comment

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

Also, this helper probably should be somewhere central, since it will need to be updated once we support the numeric seperator proposal.

Copy link
Author

@ghost ghost Aug 30, 2017

Choose a reason for hiding this comment

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

We can just use a string literal in this case then, which makes this function unnecessary. 👍

// If the user entered name for the symbol was quoted, removing the quotes is not enough, as the name could be an
// invalid identifier name. We need to check if whatever was inside the quotes is actually a valid identifier name.
// e.g "b a" is valid quoted name but when we strip off the quotes, it is invalid.
// We, thus, need to check if whatever was inside the quotes is actually a valid identifier name.
if (performCharacterChecks && !isIdentifierText(name, target)) {
return undefined;
return allowStringLiteral ? JSON.stringify(name) : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

that would be another place where a user-defined quote setting will need to be honored.

@ghost ghost merged commit 36607e1 into master Sep 6, 2017
@ghost ghost deleted the completions_quoted branch September 6, 2017 21:39
@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.

3 participants