未验证 提交 a048b6c2 编写于 作者: D David Wengier 提交者: GitHub

Don't remove leading trivia when removing suppression attributes (#47733)

上级 835f2057
......@@ -81,10 +81,13 @@ protected override Task FixAllAsync(Document document, ImmutableArray<Diagnostic
ISyntaxFacts syntaxFacts)
{
SyntaxNode node;
var options = SyntaxGenerator.DefaultRemoveOptions;
if (editor.OriginalRoot.FindNode(location.SourceSpan) is { } attribute &&
syntaxFacts.IsAttribute(attribute))
{
node = attribute;
// Keep leading trivia for attributes as we don't want to remove doc comments, or anything else
options |= SyntaxRemoveOptions.KeepLeadingTrivia;
}
else
{
......@@ -93,7 +96,7 @@ protected override Task FixAllAsync(Document document, ImmutableArray<Diagnostic
if (processedNodes.Add(node))
{
editor.RemoveNode(node);
editor.RemoveNode(node, options);
}
}
}
......
......@@ -493,9 +493,6 @@ void M()
[Fact]
public async Task TestRemoveDiagnosticSuppression_Attribute_Trivia()
{
// This test should not remove Comment1 and DocComment.
// TODO: File a bug for SyntaxEditor.RemoveNode API removing doc comment and its preceeeding trivia.
await TestInRegularAndScript1Async(
$@"
class Class
......@@ -516,6 +513,11 @@ void M()
@"
class Class
{
// Comment1
/// <summary>
/// DocComment
/// </summary>
// Comment2
// Comment4
void M()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册