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

Increase available span for 'Convert to interpolated string' refactoring #30356

Merged
merged 3 commits into from
Dec 10, 2018
Merged

Increase available span for 'Convert to interpolated string' refactoring #30356

merged 3 commits into from
Dec 10, 2018

Conversation

rik-smeets
Copy link
Contributor

Resolves #16981.

The available span where the 'Convert to interpolated string' refactoring offered is widened. The available span is now similar to the refactoring on a string.Format() statement.

For example (using the example from the referenced issue):
Console.WriteLine(3 + "Hi" + 3 + "There");

Before this change, the refactoring was only offered when the caret was touching the "Hi" or "There" strings (including quotation marks). Now, it is also offered on the non-string tokens (i.e. 3 and 5) and the plus tokens (or ampersand in VB). Lastly, it is offered when having a selection of either part of or the entire to be interpolated string.

@rik-smeets rik-smeets requested a review from a team as a code owner October 7, 2018 08:29
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

// The string literal has to at least be contained in a concatenation of some form.
// i.e. "goo" + a or a + "goo". However, those concats could be in larger
// concats as well. Walk to the top of that entire chain.

var literalExpression = token.Parent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not named property anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the comment.

{
return;
}

var cancellationToken = context.CancellationToken;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall i like this change. however, my preference is:

if we allow non-empty spans, we require that the span start/end can't be in the middle of a token. don't want someone making a random textual selection, but then getting these sorts of features. it feels pretty confusing as to what the selection/refactoring then mean IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CyrusNajmabadi I understand your preference, however, I chose to do it this way because the other 'Convert to interpolated string' refactoring works the same way. If they behave differently (as they were doing before this change), that's also confusing.

I.e. when you have:
string.Format("Hello {0} there {1}", 1, 2);
you can also have a selection, either in full or in part, and the refactoring will be offered.

I'd be happy to change it back to not allowing selections if you prefer it that way though. Please let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My personal preference is that we should continually tring to make things better, even if that leads to periods of inconsistency. :) I personally believe it would be better in both cases to not support this functionality if there is a selection that splits individual tokens. However, that doesn't mean i don't want to fix one case just because another case exists. Always be improving, and we'll continually reach better and better places. If we dont' improve things because of other issues elsewhere, we commonly reach local minimums :-/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CyrusNajmabadi You don't need to convince me, I completely agree! Just wanted to make sure you knew the difference in the similar refactoring :). I can't make the changes today anymore, I hope I can get around to it tomorrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disallowed selections again now.

@jinujoseph jinujoseph added Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Oct 8, 2018
@jinujoseph jinujoseph added this to the 16.0 milestone Oct 8, 2018
@mavasani
Copy link
Contributor

retest this please

@jinujoseph jinujoseph closed this Nov 28, 2018
@jinujoseph jinujoseph reopened this Nov 28, 2018
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

// The string literal has to at least be contained in a concatenation of some form.
// i.e. "goo" + a or a + "goo". However, those concats could be in larger
// concats as well. Walk to the top of that entire chain.

var literalExpression = token.Parent;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this now can be something other than a literal expression, maybe change the variable name to to selectedExpression. Similarly for the comment above, e.g. change "The string literal" to "The selected token"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, I have made this change.
I also rebased on master again.

Copy link
Member

@genlu genlu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM besides the nitpick

@jinujoseph jinujoseph modified the milestones: 16.0, 16.0.P2 Dec 5, 2018
@jinujoseph jinujoseph closed this Dec 10, 2018
@jinujoseph jinujoseph reopened this Dec 10, 2018
@mavasani mavasani merged commit aba2d04 into dotnet:master Dec 10, 2018
@rik-smeets rik-smeets deleted the increase-span-convert-to-interpolated-string-refactoring branch December 18, 2018 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved to merge Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants