提交 6f86e618 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #19275 from CyrusNajmabadi/objectInitializerBlankLines

Do a better job preserving blank lines when we convert code to using an object initializer.
......@@ -981,5 +981,40 @@ public void M()
}
}");
}
[WorkItem(19253, "https://github.com/dotnet/roslyn/issues/19253")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseCollectionInitializer)]
public async Task TestKeepBlankLinesAfter()
{
await TestInRegularAndScript1Async(
@"
using System.Collections.Generic;
class MyClass
{
public void Main()
{
var list = [||]new List<int>();
list.Add(1);
int horse = 1;
}
}",
@"
using System.Collections.Generic;
class MyClass
{
public void Main()
{
var list = new List<int>
{
1
};
int horse = 1;
}
}", ignoreTrivia: false);
}
}
}
\ No newline at end of file
......@@ -534,6 +534,47 @@ public void M()
}
public string Value { get; set; }
}", ignoreTrivia: false);
}
[WorkItem(19253, "https://github.com/dotnet/roslyn/issues/19253")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsUseObjectInitializer)]
public async Task TestKeepBlankLinesAfter()
{
await TestInRegularAndScript1Async(
@"
class Foo
{
public int Bar { get; set; }
}
class MyClass
{
public void Main()
{
var foo = [||]new Foo();
foo.Bar = 1;
int horse = 1;
}
}",
@"
class Foo
{
public int Bar { get; set; }
}
class MyClass
{
public void Main()
{
var foo = new Foo
{
Bar = 1
};
int horse = 1;
}
}", ignoreTrivia: false);
}
}
......
......@@ -102,7 +102,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
subEditor.ReplaceNode(statement, newStatement);
foreach (var match in matches)
{
subEditor.RemoveNode(match);
subEditor.RemoveNode(match, SyntaxRemoveOptions.KeepUnbalancedDirectives);
}
document = document.WithSyntaxRoot(subEditor.GetChangedRoot());
......
......@@ -101,7 +101,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
subEditor.ReplaceNode(statement, newStatement);
foreach (var match in matches)
{
subEditor.RemoveNode(match.Statement);
subEditor.RemoveNode(match.Statement, SyntaxRemoveOptions.KeepUnbalancedDirectives);
}
document = document.WithSyntaxRoot(subEditor.GetChangedRoot());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册