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

String interpolation refactoring doesn't work on Console.WriteLine #55053

Closed
WhiteBlackGoose opened this issue Jul 22, 2021 · 7 comments · Fixed by #55521
Closed

String interpolation refactoring doesn't work on Console.WriteLine #55053

WhiteBlackGoose opened this issue Jul 22, 2021 · 7 comments · Fixed by #55521
Assignees
Labels
4 - In Review A fix for the issue is submitted for review. Area-IDE
Milestone

Comments

@WhiteBlackGoose
Copy link

image

SDK: 6.0.100-preview.6.21355.2
VS: 17.0p2

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 22, 2021
@Youssef1313
Copy link
Member

Youssef1313 commented Jul 22, 2021

This is the expected behavior of this code refactoring. It keeps the semantics the same. Its main usage is when you have a long string containing a bunch of braces and you want to add some variables in it. See #48219

I guess the intent should be clearer by updating the title to "Convert to interpolated string (keep semantics)" or "Convert to an equivalent interpolated string" or whatever makes it clear.

@333fred
Copy link
Member

333fred commented Jul 23, 2021

Not sure I agree with that assessment. Sure, it calls a different method, but the effect is the same. We should recognize this and offer the refactoring (imo).

@Youssef1313
Copy link
Member

Youssef1313 commented Jul 23, 2021

@333fred That would be a separate analyzer with a codefix?

ie, I consider this issue as a request for a new analyzer and a codefix to handle this case, not to modify the existing refactoring.

@333fred
Copy link
Member

333fred commented Jul 23, 2021

ie, I consider this issue as a request for a new analyzer and a codefix to handle this case, not to modify the existing refactoring.

I'd defer to @CyrusNajmabadi or someone else on the IDE team to answer that question. Personally, I view it as the same thing, but I'm not a decision-maker here :)

@jmarolf jmarolf self-assigned this Jul 25, 2021
@jinujoseph jinujoseph added Bug Investigation Required and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 28, 2021
@jinujoseph jinujoseph added this to the 17.0 milestone Jul 28, 2021
@jmarolf
Copy link
Contributor

jmarolf commented Aug 3, 2021

We have this refactoring defined for methods like string.Format
image

We should update the refactoring to handle all other .NET "formatting" methods.

We just need to expand this list

var formatMethods = stringType
.GetMembers(nameof(string.Format))
.OfType<IMethodSymbol>()
.Where(ShouldIncludeFormatMethod)
.ToImmutableArray();

@jmarolf jmarolf added help wanted The issue is "up for grabs" - add a comment if you are interested in working on it and removed Investigation Required Bug labels Aug 3, 2021
@jmarolf jmarolf removed their assignment Aug 3, 2021
@Youssef1313
Copy link
Member

It looks like the same title "Convert to interpolated string" is used by different codefixes that exist for different purposes. I find this very confusing. Should this be tracked as part of this issue or do I need to create a new issue?

cc @jmarolf @CyrusNajmabadi

@jmarolf
Copy link
Contributor

jmarolf commented Aug 3, 2021

I would argue that we should only show a single refactoring for this case

that converts this:

Console.Writeline("Quack quack {0}", "duck");

to this:

Console.Writeline($"Quack quack {"duck"}");

I think it is fine to have the same text for different refactorings as long as it does what the user expects.

@jinujoseph jinujoseph added 4 - In Review A fix for the issue is submitted for review. and removed help wanted The issue is "up for grabs" - add a comment if you are interested in working on it labels Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - In Review A fix for the issue is submitted for review. Area-IDE
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants