提交 997b88ad 编写于 作者: M Martin Strecker

Remove Trivia from expression in newFieldDeclaration

上级 1f730b85
......@@ -175,6 +175,26 @@ public async Task TestFieldFix2()
await TestInRegularAndScriptAsync(code, expected, index: 1);
}
[WorkItem(21747, "https://github.com/dotnet/roslyn/issues/21747")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
public async Task TestTriviaFieldFix1()
{
var code =
@"class C
{
int i = (/* CommentLeading */ [|1 + 1|] /* CommentTrailing */) + (1 + 1);
}";
var expected =
@"class C
{
private const int {|Rename:V|} = 1 + 1;
int i = /* CommentLeading */ V /* CommentTrailing */ + V;
}";
await TestInRegularAndScriptAsync(code, expected, index: 1);
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsIntroduceVariable)]
public async Task TestConstFieldFix1()
{
......
......@@ -43,7 +43,7 @@ internal partial class CSharpIntroduceVariableService
SyntaxFactory.VariableDeclarator(
newNameToken.WithAdditionalAnnotations(RenameAnnotation.Create()),
null,
SyntaxFactory.EqualsValueClause(expression))))).WithAdditionalAnnotations(Formatter.Annotation);
SyntaxFactory.EqualsValueClause(expression.WithoutTrailingTrivia().WithoutLeadingTrivia()))))).WithAdditionalAnnotations(Formatter.Annotation);
if (oldTypeDeclaration != null)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册