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

A code refactoring to deinterpol a string #15564

Open
Tracked by #15561
psfinaki opened this issue Jul 5, 2023 · 3 comments
Open
Tracked by #15561

A code refactoring to deinterpol a string #15564

psfinaki opened this issue Jul 5, 2023 · 3 comments
Labels
Area-LangService-CodeRefactorings Suggested but not necessary code actions. Screwdrivers in VS. Feature Request
Milestone

Comments

@psfinaki
Copy link
Member

psfinaki commented Jul 5, 2023

Suggested by @T-Gro

Basically it could fix the following cases:

let x = $"test"

let y = $"{x}"

Interpolation is useless here - it decreases readability and in the second case has small perf penalty. Change the code to:

let x = "test"

let y = x

Note, $"test" compiles to the "test" so it might be not worth running a code ref in the background for this case.

@psfinaki psfinaki added the Area-LangService-CodeRefactorings Suggested but not necessary code actions. Screwdrivers in VS. label Jul 5, 2023
@github-actions github-actions bot added this to the Backlog milestone Jul 5, 2023
@abonie
Copy link
Member

abonie commented Jul 11, 2023

There are some caveats though. Noob question - can we use type information to decide whether to suggest a code refactoring or not?

Like for let x = $"test" -> let x = "test", we should avoid suggesting it if the initial line is declaring a FormattableString, like let x : System.FormattableString = $"test".
And for the second one, we have to make sure x is a string, we don't want to suggest let y = $"{42}" -> let y = 42.

@kerams
Copy link
Contributor

kerams commented Jul 11, 2023

An interpolated string with no holes compiles to a string. I'd personally not waste CPU cycles in the IDE on this.

@psfinaki
Copy link
Member Author

@abonie, yep, thanks for the notes and examples, that's good to keep in mind.

An interpolated string with no holes compiles to a string. I'd personally not waste CPU cycles in the IDE on this.

@kerams Hmm, good point. Yep, this part is probably not worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-LangService-CodeRefactorings Suggested but not necessary code actions. Screwdrivers in VS. Feature Request
Projects
None yet
Development

No branches or pull requests

4 participants