@@ -29,37 +29,57 @@ public async Task<Solution> ApplyCodeFixesAsync(
29
29
return solution ;
30
30
}
31
31
32
- var document = result . Diagnostics
32
+ var diagnostic = result . Diagnostics
33
33
. SelectMany ( kvp => kvp . Value )
34
- . Select ( diagnostic => solution . GetDocument ( diagnostic . Location . SourceTree ) )
34
+ . Where ( diagnostic => diagnostic . Location . SourceTree != null )
35
35
. FirstOrDefault ( ) ;
36
36
37
+ if ( diagnostic is null )
38
+ {
39
+ return solution ;
40
+ }
41
+
42
+ var document = solution . GetDocument ( diagnostic . Location . SourceTree ) ;
43
+
37
44
if ( document is null )
38
45
{
39
46
return solution ;
40
47
}
41
48
49
+ CodeAction ? action = null ;
50
+ var context = new CodeFixContext ( document , diagnostic ,
51
+ ( a , _ ) =>
52
+ {
53
+ if ( action == null )
54
+ {
55
+ action = a ;
56
+ }
57
+ } ,
58
+ cancellationToken ) ;
59
+
60
+ await codeFix . RegisterCodeFixesAsync ( context ) . ConfigureAwait ( false ) ;
61
+
42
62
var fixAllContext = new FixAllContext (
43
63
document : document ,
44
64
codeFixProvider : codeFix ,
45
65
scope : FixAllScope . Solution ,
46
- codeActionEquivalenceKey : null ! , // FixAllState supports null equivalence key. This should still be supported.
66
+ codeActionEquivalenceKey : action ? . EquivalenceKey ! , // FixAllState supports null equivalence key. This should still be supported.
47
67
diagnosticIds : new [ ] { diagnosticId } ,
48
68
fixAllDiagnosticProvider : new DiagnosticProvider ( result ) ,
49
69
cancellationToken : cancellationToken ) ;
50
70
51
71
try
52
72
{
53
- var action = await fixAllProvider . GetFixAsync ( fixAllContext ) . ConfigureAwait ( false ) ;
54
- if ( action is null )
73
+ var fixAllAction = await fixAllProvider . GetFixAsync ( fixAllContext ) . ConfigureAwait ( false ) ;
74
+ if ( fixAllAction is null )
55
75
{
56
76
logger . LogWarning ( Resources . Unable_to_fix_0_Code_fix_1_didnt_return_a_Fix_All_action , diagnosticId , codeFix . GetType ( ) . Name ) ;
57
77
return solution ;
58
78
}
59
79
60
- var operations = await action . GetOperationsAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
80
+ var operations = await fixAllAction . GetOperationsAsync ( cancellationToken ) . ConfigureAwait ( false ) ;
61
81
var applyChangesOperation = operations . OfType < ApplyChangesOperation > ( ) . SingleOrDefault ( ) ;
62
- if ( action is null )
82
+ if ( applyChangesOperation is null )
63
83
{
64
84
logger . LogWarning ( Resources . Unable_to_fix_0_Code_fix_1_returned_an_unexpected_operation , diagnosticId , codeFix . GetType ( ) . Name ) ;
65
85
return solution ;
0 commit comments