Skip to content
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

Don't offer Convert to template string refactoring for simple strings #36784

Closed
mjbvz opened this issue Feb 13, 2020 · 4 comments · Fixed by #36785
Closed

Don't offer Convert to template string refactoring for simple strings #36784

mjbvz opened this issue Feb 13, 2020 · 4 comments · Fixed by #36785
Assignees
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Fixed A PR has been merged for this issue

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Feb 13, 2020

TypeScript Version: 3.8.1-rc

Search Terms:

  • refactor
  • refactoring
  • code actions

Repo
For code such as

import ImageEditor from 'tui-image-editor';

Place cursor on the string

Bug:
A convert to template string refactoring is offered. This is not helpful.

I suggest that we only show convert to template string if you are on a string concatenation expression.

@DanielRosenwasser
Copy link
Member

So clearly this is silly because there are certain positions where a template string isn't valid - I think it'd probably be okay to disable this for simple strings, but we should revisit whether we want to enable it for all strings and disable it for nonsensical positions like

  • import/export specifiers
  • Property names
  • Maybe other stuff?

@mjbvz
Copy link
Contributor Author

mjbvz commented Feb 13, 2020

I'd prefer to only see this refactoring when the cursor on a string concatenation expression

Also, we probably want to fix this for 3.8 (either for the final release or in a recovery build) as it is rather annoying to have the lightbulb show up for every string

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol labels Feb 13, 2020
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 3.8.2 milestone Feb 13, 2020
@DanielRosenwasser DanielRosenwasser self-assigned this Feb 13, 2020
@DanielRosenwasser DanielRosenwasser added the Fixed A PR has been merged for this issue label Feb 13, 2020
@treybrisbane
Copy link

Just as a contrasting opinion, I actually find this behavior useful (in cases where template strings would be legal). After using TS/JS for years, my muscle memory now defaults to ${...} rather than + to template values into strings, and it's nice to be able to quickly convert the string in question to a template string in cases where it isn't already.

That said @DanielRosenwasser, another potential approach could be to make the suggestion if the string in question contains ${. Just a thought. 🙂

@nicoespeon
Copy link

Hey there 👋

A quick heads-up to support @treybrisbane point of view.

For the context, I'm the author of a VS Code extension that provides JS & TS refactorings. We used to provide "Convert to Template Literal". We removed it since it's now handled by the editor, through TypeScript.

However, it was very valid (and convenient) to switch from:

const a = "I have some apples";

to

const a = `I have some apples`;

To start inserting variables inside.

I understand this was dropped as a side-effect of a bug fix. I think what we really want to avoid is proposing the refactoring for invalid things like imports. I implemented that kind of check in my extension indeed.

You can check nicoespeon/abracadabra#94 for more context on this.

If you need more details, I'd be happy to help 😄
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants