Skip to content

Commit a421802

Browse files
committed
Remove DescendantNodesAndSelf() from code fixer
1 parent 5fe5e5e commit a421802

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

src/CommunityToolkit.Mvvm.CodeFixers/ClassUsingAttributeInsteadOfInheritanceCodeFixer.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System;
65
using System.Collections.Immutable;
76
using System.Composition;
8-
using System.Linq;
9-
using System.Threading;
107
using System.Threading.Tasks;
118
using CommunityToolkit.Mvvm.SourceGenerators;
129
using Microsoft.CodeAnalysis;
@@ -54,22 +51,19 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
5451

5552
SyntaxNode? root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
5653

57-
foreach (SyntaxNode syntaxNode in root!.FindNode(diagnosticSpan).DescendantNodesAndSelf())
54+
// Get the class declaration from the target diagnostic
55+
if (root!.FindNode(diagnosticSpan) is ClassDeclarationSyntax { Identifier.Text: string identifierName } classDeclaration &&
56+
identifierName == typeName)
5857
{
59-
// Find the first descendant node from the source of the diagnostic that is a class declaration with the target name
60-
if (syntaxNode is ClassDeclarationSyntax { Identifier.Text: string identifierName } classDeclaration &&
61-
identifierName == typeName)
62-
{
63-
// Register the code fix to update the class declaration to inherit from ObservableObject instead
64-
context.RegisterCodeFix(
65-
CodeAction.Create(
66-
title: "Inherit from ObservableObject",
67-
createChangedDocument: token => UpdateReference(context.Document, root, classDeclaration, attributeTypeName),
68-
equivalenceKey: "Inherit from ObservableObject"),
69-
diagnostic);
58+
// Register the code fix to update the class declaration to inherit from ObservableObject instead
59+
context.RegisterCodeFix(
60+
CodeAction.Create(
61+
title: "Inherit from ObservableObject",
62+
createChangedDocument: token => UpdateReference(context.Document, root, classDeclaration, attributeTypeName),
63+
equivalenceKey: "Inherit from ObservableObject"),
64+
diagnostic);
7065

71-
return;
72-
}
66+
return;
7367
}
7468
}
7569

0 commit comments

Comments
 (0)