Skip to content

Fix commit characters in typescript property key strings, and improve completion tests #250451

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ashleylamont
Copy link

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:

const myObject = { foo: "bar" };

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:

  1. In a property
  2. Currently inside an un-paired quote (in the line text before the cursor)

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).

@ashleylamont ashleylamont force-pushed the ashleylamont/fix-typescript-obj-key-commit-chars branch from 05b2014 to a9290e9 Compare June 3, 2025 11:17
@Tyriar Tyriar assigned mjbvz and unassigned Tyriar Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Commit characters are not reset inside typescript object property key strings
3 participants