diff --git a/src/EditorFeatures/CSharpTest/CodeActions/MoveType/MoveTypeTests.MoveToNewFile.cs b/src/EditorFeatures/CSharpTest/CodeActions/MoveType/MoveTypeTests.MoveToNewFile.cs
index 69a6613dd6a2eb56dfa7ee330e6db322f5730428..6e8e647dd5346842c94249e89c011de3875bd1f3 100644
--- a/src/EditorFeatures/CSharpTest/CodeActions/MoveType/MoveTypeTests.MoveToNewFile.cs
+++ b/src/EditorFeatures/CSharpTest/CodeActions/MoveType/MoveTypeTests.MoveToNewFile.cs
@@ -54,7 +54,7 @@ class Class2 { }";
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
[WorkItem(14008, "https://github.com/dotnet/roslyn/issues/14008")]
- public async Task TestFolders()
+ public async Task TestMoveToNewFileWithFolders()
{
var code =
@"
diff --git a/src/EditorFeatures/CSharpTest/CodeActions/MoveType/MoveTypeTests.RenameFile.cs b/src/EditorFeatures/CSharpTest/CodeActions/MoveType/MoveTypeTests.RenameFile.cs
index 89eebad96dfe2a34973f3be13758c7bd046eb7b4..671ce88fc3adcb54e4f2b6cd07048c951c4d8337 100644
--- a/src/EditorFeatures/CSharpTest/CodeActions/MoveType/MoveTypeTests.RenameFile.cs
+++ b/src/EditorFeatures/CSharpTest/CodeActions/MoveType/MoveTypeTests.RenameFile.cs
@@ -33,6 +33,28 @@ class Inner { }
await TestRenameFileToMatchTypeAsync(code, expectedDocumentName);
}
+ [WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
+ public async Task TestRenameFileWithFolders()
+ {
+ var code =
+@"
+
+
+
+[||]class Class1
+{
+ class Inner { }
+}
+
+
+";
+
+ var expectedDocumentName = "Class1.cs";
+
+ await TestRenameFileToMatchTypeAsync(code, expectedDocumentName,
+ destinationDocumentContainers: new[] { "A", "B" });
+ }
+
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
public async Task TestMissing_TypeNameMatchesFileName_RenameFile()
{
diff --git a/src/EditorFeatures/Test/MoveType/AbstractMoveTypeTest.cs b/src/EditorFeatures/Test/MoveType/AbstractMoveTypeTest.cs
index 2f20d8b15384b4bdf382f336bb25da701f5eb804..0ceb89dac9f27824421035fee00ddd0cd4a2f152 100644
--- a/src/EditorFeatures/Test/MoveType/AbstractMoveTypeTest.cs
+++ b/src/EditorFeatures/Test/MoveType/AbstractMoveTypeTest.cs
@@ -73,7 +73,8 @@ protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspa
string originalCode,
string expectedDocumentName = null,
bool expectedCodeAction = true,
- bool compareTokens = true)
+ bool compareTokens = true,
+ IList destinationDocumentContainers = null)
{
using (var workspace = await CreateWorkspaceFromFileAsync(originalCode, parseOptions: null, compilationOptions: null))
{
@@ -82,10 +83,8 @@ protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspa
Assert.True(expectedDocumentName != null, $"{nameof(expectedDocumentName)} should be present if {nameof(expectedCodeAction)} is true.");
var oldDocumentId = workspace.Documents[0].Id;
-
- string expectedText;
- IList spans;
- MarkupTestFile.GetSpans(originalCode, out expectedText, out spans);
+ var expectedText = workspace.Documents[0].TextBuffer.CurrentSnapshot.GetText();
+ var spans = workspace.Documents[0].SelectedSpans;
var codeActionTitle = string.Format(RenameFileCodeActionTitle, expectedDocumentName);
@@ -96,6 +95,12 @@ protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspa
// the original source document does not exist in the new solution.
var newSolution = oldSolutionAndNewSolution.Item2;
Assert.Null(newSolution.GetDocument(oldDocumentId));
+
+ if (destinationDocumentContainers != null)
+ {
+ var newDocument = newSolution.Projects.First().Documents.First();
+ Assert.Equal(destinationDocumentContainers, newDocument.Folders);
+ }
}
else
{
diff --git a/src/Features/Core/Portable/CodeRefactorings/MoveType/AbstractMoveTypeService.RenameFileEditor.cs b/src/Features/Core/Portable/CodeRefactorings/MoveType/AbstractMoveTypeService.RenameFileEditor.cs
index 40ed8cb6f3de776177e04d814addd47986d8f07a..55ec00c0d0b00aa9e3667eb3dce9045aa03a2f55 100644
--- a/src/Features/Core/Portable/CodeRefactorings/MoveType/AbstractMoveTypeService.RenameFileEditor.cs
+++ b/src/Features/Core/Portable/CodeRefactorings/MoveType/AbstractMoveTypeService.RenameFileEditor.cs
@@ -26,16 +26,17 @@ internal override Task> GetOperationsAsync()
///
private IEnumerable RenameFileToMatchTypeName()
{
- var solution = SemanticDocument.Document.Project.Solution;
+ var oldDocument = SemanticDocument.Document;
+ var solution = oldDocument.Project.Solution;
var text = SemanticDocument.Text;
- var oldDocumentId = SemanticDocument.Document.Id;
- var newDocumentId = DocumentId.CreateNewId(SemanticDocument.Document.Project.Id, FileName);
+ var oldDocumentId = oldDocument.Id;
+ var newDocumentId = DocumentId.CreateNewId(oldDocument.Project.Id, FileName);
// currently, document rename is accomplished by a remove followed by an add.
// the workspace takes care of resolving conflicts if the document name is not unique in the project
// by adding numeric suffixes to the new document being added.
var newSolution = solution.RemoveDocument(oldDocumentId);
- newSolution = newSolution.AddDocument(newDocumentId, FileName, text);
+ newSolution = newSolution.AddDocument(newDocumentId, FileName, text, oldDocument.Folders);
return new CodeActionOperation[]
{