Fix commit characters in typescript property key strings, and improve completion tests #250451
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why is this changing?
This PR fixes #250255 relating to commit characters and completions inside typescript property key strings.
The linked issue has more details and a recording, but in summary, given the following code:
the current behaviour is that when completing a property, e.g. in an index access like
myObject["foo"]
, typing an existing commit character such as.
or(
will accept the first suggestion and enter that character.This can be particularly problematic in scenarios where property keys may contain those characters, such as when they represent CSS selectors (e.g. when using emotion), as then typing in the name of a valid key will cause the first suggestion to be accepted.
What is changing?
This PR modifies the behaviour of TypeScript completions to check if the cursor is currently:
and if so, replaces the default commit characters (characters that will trigger a suggestion to be accepted) with the relevant quote character that would close the current string.
This means that when typing out a property key, pressing
.
will not complete if you are inside a string, but instead will just type the character, while typing the quote that you used to start the string will complete the next suggestion.Testing plan
New tests have been added for both the positive case (completing on quotes) and the negative case (not completing on non-quotes).
The testing setup for typescript completions has also been improved with this, to streamline some timing conditions that were unnecessary, and to reduce the scope of skipping in this suite to only the tests that are presently flaky (from my observations).