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

Port from CSharpEssentials of Convert-To-Interpolated-String #11415

Merged
merged 3 commits into from
Jun 3, 2016

Conversation

jmarolf
Copy link
Contributor

@jmarolf jmarolf commented May 19, 2016

No description provided.

@jmarolf
Copy link
Contributor Author

jmarolf commented May 19, 2016

@dotnet/roslyn-ide

@jmarolf jmarolf force-pushed the interpolated-string-refactoring branch 2 times, most recently from 0523c51 to 9c375ea Compare May 19, 2016 07:39
{
internal partial class ConvertToInterpolatedStringRefactoringProvider
{
private class InterpolatedStringRewriter : CSharpSyntaxRewriter
Copy link
Member

Choose a reason for hiding this comment

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

Since you're only rewriting InterpolationSyntax, couldn't you call ReplaceNodes rather than creating a rewriter?

@DustinCampbell
Copy link
Member

Could you describe what the custom formatting rule is used for and why it should be specific to this refactoring rather than pushing it down into the formatting engine?

@jmarolf
Copy link
Contributor Author

jmarolf commented May 19, 2016

@DustinCampbell today the formatting ending will always place /* Multiline Comments */ on a newline (ElasticTriviaFormattingRule). We need to have this not happen in an interpolation as non-verbatim strings don't allow interpolations to be on multiple lines. I can have a look at the formatting engine rules and see. If we can detect that we are in this case generally then this should just be a part of the formatting engine.

@jmarolf jmarolf force-pushed the interpolated-string-refactoring branch from 9c375ea to 25ebeb2 Compare May 19, 2016 21:52
}

[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsConvertToInterpolatedString)]
public async Task TestItemOutsideRange()
Copy link
Member

Choose a reason for hiding this comment

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

Is this what we actually want? Yes the old code is broken but this seems a pretty strange way to "improve" it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we want to trigger a warning? Would you prefer us to not offer the refactoring in this case? Typically always allow a user to perform a refactoring, even if their code doesn't make sense

Copy link
Member

Choose a reason for hiding this comment

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

I'm not following what you guys are talking about here. The test range below seems reasonable to me.

@DustinCampbell
Copy link
Member

@jmarolf -- shouldn't we just make the elastic trivia rule smarter? Otherwise, any generate code going into an interpolation would have to do the same thing.

@jmarolf
Copy link
Contributor Author

jmarolf commented May 22, 2016

@DustinCampbell I agree, I'll work on fixing up the formatter for interpolated strings and remove the custom formatting logic.

@jmarolf jmarolf force-pushed the interpolated-string-refactoring branch from 25ebeb2 to 63dde06 Compare May 31, 2016 23:09
removing syntax rewriter and incorporating formatting rules into formatter
@jmarolf jmarolf force-pushed the interpolated-string-refactoring branch from 63dde06 to 725c75d Compare May 31, 2016 23:12
@jmarolf
Copy link
Contributor Author

jmarolf commented Jun 1, 2016

retest windows_vsi_p2_open_prtest please

namespace Microsoft.CodeAnalysis.CSharp.CodeRefactorings.ConvertToInterpolatedString
{
[ExportCodeRefactoringProvider(LanguageNames.CSharp, Name = PredefinedCodeRefactoringProviderNames.ConvertToInterpolatedString), Shared]
internal partial class ConvertToInterpolatedStringRefactoringProvider : AbstractConvertToInterpolatedStringRefactoringProvider<InterpolatedStringExpressionSyntax, InvocationExpressionSyntax, ExpressionSyntax, ArgumentSyntax, LiteralExpressionSyntax>
Copy link
Member

Choose a reason for hiding this comment

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

wrap

formatMethods As ImmutableArray(Of ISymbol),
semanticModel As SemanticModel,
cancellationToken As CancellationToken) As Boolean
If (invocation.ArgumentList IsNot Nothing AndAlso
Copy link
Member

Choose a reason for hiding this comment

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

This logic also looks teh same as the C# version. Can we pull up into the base type?

@jmarolf jmarolf force-pushed the interpolated-string-refactoring branch from 18e0fd5 to 6ad9b9c Compare June 2, 2016 06:07
protected override InterpolatedStringExpressionSyntax GetInterpolatedString(string text) =>
ParseExpression("$" + text) as InterpolatedStringExpressionSyntax;

protected override LiteralExpressionSyntax GetLiteralExpressionSyntax(SeparatedSyntaxList<ArgumentSyntax> arguments) =>
Copy link
Member

Choose a reason for hiding this comment

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

How is this function different from GetFirstArgument?

@jmarolf jmarolf force-pushed the interpolated-string-refactoring branch from 6ad9b9c to 6037af5 Compare June 2, 2016 07:49
protected override SyntaxList<InterpolatedStringContentSyntax> GetInterpolatedStringContents(InterpolatedStringExpressionSyntax interpolatedString) =>
interpolatedString.Contents;

protected override SyntaxNode ReplaceExpressionInInterpolation(InterpolationSyntax node, ExpressionSyntax expressionSyntax) =>
Copy link
Member

Choose a reason for hiding this comment

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

Could be lifted up to the base type. Just call. "node.ReplaceNode(GetExpressionOfInterpolation(), expressionSyntax)"

@CyrusNajmabadi
Copy link
Member

LGTM. Mainly nits at ths point.

@jmarolf jmarolf force-pushed the interpolated-string-refactoring branch 2 times, most recently from 9967351 to 9b84412 Compare June 3, 2016 00:38
@@ -573,5 +573,15 @@ IEnumerator IEnumerable.GetEnumerator()

return SpecializedCollections.EmptyEnumerator<TNode>();
}

public static implicit operator SeparatedSyntaxList<SyntaxNode>(SeparatedSyntaxList<TNode> nodes)
Copy link
Member

Choose a reason for hiding this comment

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

@dotnet/roslyn-compiler Please take a look at this. Current SyntaxList<T> has these operators, but we missed them for SeparatedSyntaxList. Anyone have a problem with us adding this?

Copy link
Member

Choose a reason for hiding this comment

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

Seems reasonable.


In reply to: 65642745 [](ancestors = 65642745)

- general logic cleanup
- moving methods to abstract base class
@jmarolf jmarolf force-pushed the interpolated-string-refactoring branch from 9b84412 to baf565f Compare June 3, 2016 05:55
@jmarolf
Copy link
Contributor Author

jmarolf commented Jun 3, 2016

test vsi please

@jmarolf jmarolf merged commit d8ac28e into dotnet:future Jun 3, 2016
@jmarolf jmarolf deleted the interpolated-string-refactoring branch July 13, 2020 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants