提交 2b88c7e6 编写于 作者: C CyrusNajmabadi

Don't create unbalanced trivia when moving types.

上级 92c529d1
......@@ -944,5 +944,57 @@ 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);
}
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.Shared.Extensions;
namespace Microsoft.CodeAnalysis.CodeFixes.Async
{
......@@ -42,7 +43,7 @@ internal abstract partial class AbstractAddAwaitCodeFixProvider : AbstractAsyncC
protected static bool TryGetTaskType(SemanticModel semanticModel, out INamedTypeSymbol taskType)
{
var compilation = semanticModel.Compilation;
taskType = compilation.GetTypeByMetadataName("System.Threading.Tasks.Task");
taskType = compilation.TaskType();
return taskType != null;
}
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册