-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
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 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.
src/services/completions.ts
Outdated
} | ||
|
||
return name; | ||
} | ||
|
||
function isNumericLiteralText(name: string): boolean { | ||
return /^-?\d+(\.\d+)?(e\d+)?$/.test(name); |
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.
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 -?
?
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.
Also, this helper probably should be somewhere central, since it will need to be updated once we support the numeric seperator proposal.
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 can just use a string literal in this case then, which makes this function unnecessary. 👍
…nd use string literals for number keys
src/services/completions.ts
Outdated
// 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; |
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.
that would be another place where a user-defined quote setting will need to be honored.
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