p42ai / js-assistant

120+ refactorings and code-assists for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=p42ai.refactor
MIT License
125 stars 8 forks source link

Provide a good story for string literal <-> template strings conversion #32

Closed hediet closed 2 years ago

hediet commented 2 years ago

I usually start with a string literal ("hello world") and later want to convert it to `hello ${name}`.

While the code actions are nice, I think the story can be improved.

I'm thinking of automatic conversion from a normal string to a template string once the user types the first ${}, and the opposite direction once the users removes the last ${}.

Also, the conversion code action should keep the cursor at its position in the string (use two edits for the prefix and suffix instead a single one for the entire string).

lgrammel commented 2 years ago

That's a brilliant idea, I want that feature! I'll look into implementing it in the coming weeks.

lgrammel commented 2 years ago

A first improvement is coming in v1.125.0 - the cursor should not move any more when applying the "convert string to template literal" and "convert template literal to string" code actions.

lgrammel commented 2 years ago

The Template String Converter extension adds this functionality. It's a little bit different from the existing code assists, so I'll not add this to P42 at this point, especially since it's already available in another extension.