提交 93bc7340 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #18030 from CyrusNajmabadi/moveTypeDirectivew

Don't create unbalanced trivia when moving types.
......@@ -84,7 +84,7 @@ class Class2 { }
var destinationDocumentText = @"class Class1 { }";
await TestMoveTypeToNewFileAsync(
code, codeAfterMove, expectedDocumentName,
code, codeAfterMove, expectedDocumentName,
destinationDocumentText, destinationDocumentContainers: ImmutableArray.Create("A", "B"));
}
......@@ -115,7 +115,7 @@ class Class2 { }";
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
public async Task MoveTypeWithNoContainerNamespace()
{
var code =
var code =
@"[||]class Class1 { }
class Class2 { }";
var codeAfterMove = @"class Class2 { }";
......@@ -143,7 +143,7 @@ class Class2 { }";
class Class2 { }";
var expectedDocumentName = "Class1.cs";
var destinationDocumentText =
var destinationDocumentText =
@"class Class1 { }";
await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText);
......@@ -944,5 +944,115 @@ class Inner : IWhatever {
await TestMoveTypeToNewFileAsync(
code, codeAfterMove, expectedDocumentName, destinationDocumentText);
}
[WorkItem(17930, "https://github.com/dotnet/roslyn/issues/17930")]
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
public async Task MoveTypeWithDirectives1()
{
var code =
@"using System;
namespace N
{
class Program
{
static void Main()
{
}
}
}
#if true
public class [||]Inner
{
}
#endif";
var codeAfterMove =
@"using System;
namespace N
{
class Program
{
static void Main()
{
}
}
}
#if true
#endif";
var expectedDocumentName = "Inner.cs";
var destinationDocumentText =
@"#if true
public class Inner
{
}
#endif";
await TestMoveTypeToNewFileAsync(
code, codeAfterMove, expectedDocumentName, destinationDocumentText, ignoreTrivia: false);
}
[WorkItem(17930, "https://github.com/dotnet/roslyn/issues/17930")]
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
public async Task MoveTypeWithDirectives2()
{
var code =
@"using System;
namespace N
{
class Program
{
static void Main()
{
}
#if true
public class [||]Inner
{
}
#endif
}
}";
var codeAfterMove =
@"using System;
namespace N
{
partial class Program
{
static void Main()
{
}
#if true
#endif
}
}";
var expectedDocumentName = "Inner.cs";
var destinationDocumentText =
@"namespace N
{
partial class Program
{
#if true
public class Inner
{
}
#endif
}
}";
await TestMoveTypeToNewFileAsync(
code, codeAfterMove, expectedDocumentName, destinationDocumentText, ignoreTrivia: false);
}
}
}
\ No newline at end of file
......@@ -157,7 +157,7 @@ private async Task<SyntaxNode> AddFinalNewLineIfDesired(Document document, Synta
// original attributes and we don't want to mess with them.
AddPartialModifiersToTypeChain(documentEditor,
removeAttributesAndComments: false, removeTypeInheritance: false);
documentEditor.RemoveNode(State.TypeNode, SyntaxRemoveOptions.KeepNoTrivia);
documentEditor.RemoveNode(State.TypeNode, SyntaxRemoveOptions.KeepUnbalancedDirectives);
var updatedDocument = documentEditor.GetChangedDocument();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册