|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 | // See the LICENSE file in the project root for more information.
|
4 | 4 |
|
5 |
| -using System; |
6 | 5 | using System.Collections.Immutable;
|
7 | 6 | using System.Composition;
|
8 |
| -using System.Linq; |
9 |
| -using System.Threading; |
10 | 7 | using System.Threading.Tasks;
|
11 | 8 | using CommunityToolkit.Mvvm.SourceGenerators;
|
12 | 9 | using Microsoft.CodeAnalysis;
|
@@ -54,22 +51,19 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
|
54 | 51 |
|
55 | 52 | SyntaxNode? root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);
|
56 | 53 |
|
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) |
58 | 57 | {
|
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); |
70 | 65 |
|
71 |
| - return; |
72 |
| - } |
| 66 | + return; |
73 | 67 | }
|
74 | 68 | }
|
75 | 69 |
|
|
0 commit comments