@@ -27,7 +27,7 @@ internal class SA1517CodeFixProvider : CodeFixProvider
2727 /// <inheritdoc/>
2828 public override FixAllProvider GetFixAllProvider ( )
2929 {
30- return CustomFixAllProviders . BatchFixer ;
30+ return FixAll . Instance ;
3131 }
3232
3333 /// <inheritdoc/>
@@ -47,6 +47,13 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)
4747 }
4848
4949 private static async Task < Document > GetTransformedDocumentAsync ( Document document , CancellationToken token )
50+ {
51+ var newSyntaxRoot = await GetTransformedSyntaxRootAsync ( document , token ) . ConfigureAwait ( false ) ;
52+
53+ return document . WithSyntaxRoot ( newSyntaxRoot ) ;
54+ }
55+
56+ private static async Task < SyntaxNode > GetTransformedSyntaxRootAsync ( Document document , CancellationToken token )
5057 {
5158 var syntaxRoot = await document . GetSyntaxRootAsync ( token ) . ConfigureAwait ( false ) ;
5259
@@ -66,9 +73,26 @@ private static async Task<Document> GetTransformedDocumentAsync(Document documen
6673
6774 var newFirstToken = firstToken . WithLeadingTrivia ( newTriviaList ) ;
6875 var newSyntaxRoot = syntaxRoot . ReplaceToken ( firstToken , newFirstToken ) ;
69- var newDocument = document . WithSyntaxRoot ( newSyntaxRoot ) ;
76+ return newSyntaxRoot ;
77+ }
78+
79+ private class FixAll : DocumentBasedFixAllProvider
80+ {
81+ public static FixAllProvider Instance { get ; } =
82+ new FixAll ( ) ;
7083
71- return newDocument ;
84+ protected override string CodeActionTitle =>
85+ LayoutResources . SA1517CodeFix ;
86+
87+ protected override Task < SyntaxNode > FixAllInDocumentAsync ( FixAllContext fixAllContext , Document document , ImmutableArray < Diagnostic > diagnostics )
88+ {
89+ if ( diagnostics . IsEmpty )
90+ {
91+ return null ;
92+ }
93+
94+ return GetTransformedSyntaxRootAsync ( document , fixAllContext . CancellationToken ) ;
95+ }
7296 }
7397 }
7498}
0 commit comments