diff --git a/src/EditorFeatures/CSharpTest/CodeActions/SyncNamespace/CSharpSyncNamespaceTestsBase.cs b/src/EditorFeatures/CSharpTest/CodeActions/SyncNamespace/CSharpSyncNamespaceTestsBase.cs index ce4ead19a80b1a04c4ab82f124a4c1bd9070c538..8742bbc8d61ecb77a7c738ff6fdc3253530ce5c5 100644 --- a/src/EditorFeatures/CSharpTest/CodeActions/SyncNamespace/CSharpSyncNamespaceTestsBase.cs +++ b/src/EditorFeatures/CSharpTest/CodeActions/SyncNamespace/CSharpSyncNamespaceTestsBase.cs @@ -169,7 +169,6 @@ protected async Task TestMoveFileToMatchNamespace(string initialMarkup, List(), "File2.cs"); + var code = +$@" + + + +namespace [||]{declaredNamespace} +{{ + class Class1 + {{ + }} + + class Class2 + {{ + }} +}} + +using Foo.Bar.Baz; + +namespace Foo +{{ + class RefClass + {{ + private Class1 c1; + + void M1() + {{ + Bar.Baz.Class2 c2 = null; + }} + }} +}} + +"; + + var expectedSourceOriginal = +@"namespace A.B.C +{ + class Class1 + { + } + + class Class2 + { + } +}"; + await TestChangeNamespaceAsync(code, expectedSourceOriginal); + } + [WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsSyncNamespace)] public async Task ChangeNamespace_WithQualifiedReferencesInOtherDocument() { diff --git a/src/Features/Core/Portable/CodeRefactorings/SyncNamespace/AbstractChangeNamespaceService.cs b/src/Features/Core/Portable/CodeRefactorings/SyncNamespace/AbstractChangeNamespaceService.cs index 599ed808c46eb483e35e557903796c02fd4e6512..445ab2d3845bb11dc4eb23a5eabec6b2f5f93134 100644 --- a/src/Features/Core/Portable/CodeRefactorings/SyncNamespace/AbstractChangeNamespaceService.cs +++ b/src/Features/Core/Portable/CodeRefactorings/SyncNamespace/AbstractChangeNamespaceService.cs @@ -188,7 +188,9 @@ await ChangeNamespaceInSingleDocumentAsync(solutionAfterNamespaceChange, documen ImmutableArray.Create(declaredNamespace, targetNamespace), cancellationToken).ConfigureAwait(false); - return await MergeDiffAsync(solutionAfterFirstMerge, solutionAfterImportsRemoved, cancellationToken).ConfigureAwait(false); + var mergedSolution = await MergeDiffAsync(solutionAfterFirstMerge, solutionAfterImportsRemoved, cancellationToken).ConfigureAwait(false); + + return await mergedSolution.ExcludeDisallowedDocumentTextChangesAsync(solution, cancellationToken).ConfigureAwait(false); } finally {