Skip to content

Commit

Permalink
Use WithTriviaFrom(currentAssignment) and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MaStr11 committed Jun 23, 2021
1 parent d7199c5 commit 9e428fe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,36 @@ int M(int i)
}}
}}",
@$"public class C
{{
int M(int i)
{{
{after}
}}
}}");
}

[WorkItem(38054, "https://github.com/dotnet/roslyn/issues/53969")]
[Theory, Trait(Traits.Feature, Traits.Features.CodeActionsUseCompoundAssignment)]
[InlineData(
"/* Before */ i [||]= i + 1; /* After */",
"/* Before */ i++; /* After */")]
[InlineData(
"M( /* Before */ i [||]= i + 1 /* After */ );",
"M( /* Before */ ++i /* After */ );")]
[InlineData(
"M( /* Before */ i [||]= i - 1 /* After */ );",
"M( /* Before */ --i /* After */ );")]
public async Task TestTriviaPreserved(string before, string after)
{
await TestInRegularAndScript1Async(
@$"public class C
{{
int M(int i)
{{
{before}
}}
}}",
@$"public class C
{{
int M(int i)
{{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ protected override Task FixAllAsync(
if (diagnostic.Properties.ContainsKey(UseCompoundAssignmentUtilities.Increment))
{
return Increment((TExpressionSyntax)leftOfAssign.WithoutTrailingTrivia(), postfix: syntaxFacts.IsSimpleAssignmentStatement(currentAssignment.Parent));
return Increment((TExpressionSyntax)leftOfAssign.WithTriviaFrom(currentAssignment), postfix: syntaxFacts.IsSimpleAssignmentStatement(currentAssignment.Parent));

This comment has been minimized.

Copy link
@CyrusNajmabadi

CyrusNajmabadi Jun 23, 2021

Member

what i mean is:

Increment((TExpressionSyntax)leftOfAssign, postfix: syntaxFacts.IsSimpleAssignmentStatement(currentAssignment.Parent)).WithTriviaFrom(currentAssignment)

}
if (diagnostic.Properties.ContainsKey(UseCompoundAssignmentUtilities.Decrement))
{
return Decrement((TExpressionSyntax)leftOfAssign.WithoutTrailingTrivia(), postfix: syntaxFacts.IsSimpleAssignmentStatement(currentAssignment.Parent));
return Decrement((TExpressionSyntax)leftOfAssign.WithTriviaFrom(currentAssignment), postfix: syntaxFacts.IsSimpleAssignmentStatement(currentAssignment.Parent));
}
var assignmentOpKind = _binaryToAssignmentMap[syntaxKinds.Convert<TSyntaxKind>(rightOfAssign.RawKind)];
Expand Down

0 comments on commit 9e428fe

Please sign in to comment.