@@ -36,10 +36,7 @@ private sealed partial class RegularCompilationTracker : ICompilationTracker
36
36
Compilation ? compilationWithStaleGeneratedTrees ,
37
37
CancellationToken cancellationToken )
38
38
{
39
- var canSkipRunningGenerators = creationPolicy . GeneratedDocumentCreationPolicy is GeneratedDocumentCreationPolicy . DoNotCreate
40
- || ( creationPolicy . GeneratedDocumentCreationPolicy is GeneratedDocumentCreationPolicy . CreateOnlyRequired
41
- && ! await HasRequiredGeneratorsAsync ( compilationState , cancellationToken ) . ConfigureAwait ( false ) ) ;
42
-
39
+ var canSkipRunningGenerators = await CanSkipRunningGeneratorsAsync ( creationPolicy , compilationState , cancellationToken ) . ConfigureAwait ( false ) ;
43
40
if ( canSkipRunningGenerators )
44
41
{
45
42
// We're either frozen, or we only want required generators and know that there aren't any to run, so we
@@ -78,6 +75,23 @@ private sealed partial class RegularCompilationTracker : ICompilationTracker
78
75
cancellationToken ) . ConfigureAwait ( false ) ;
79
76
return ( compilationWithGeneratedFiles , new ( nextGeneratedDocuments , nextGeneratorDriver ) ) ;
80
77
}
78
+
79
+ async ValueTask < bool > CanSkipRunningGeneratorsAsync ( CreationPolicy creationPolicy , SolutionCompilationState compilationState , CancellationToken cancellationToken )
80
+ {
81
+ // if we don't want to create generated documents, we can skip
82
+ if ( creationPolicy . GeneratedDocumentCreationPolicy is GeneratedDocumentCreationPolicy . DoNotCreate )
83
+ return true ;
84
+
85
+ // if we only want required documents, we can skip if we don't have any required generators
86
+ if ( creationPolicy . GeneratedDocumentCreationPolicy is GeneratedDocumentCreationPolicy . CreateOnlyRequired )
87
+ {
88
+ var hasRequiredGenerators = await HasRequiredGeneratorsAsync ( compilationState , cancellationToken ) . ConfigureAwait ( false ) ;
89
+ return ! hasRequiredGenerators ;
90
+ }
91
+
92
+ // we need to run generators
93
+ return false ;
94
+ }
81
95
}
82
96
83
97
private async Task < bool > HasRequiredGeneratorsAsync ( SolutionCompilationState compilationState , CancellationToken cancellationToken )
0 commit comments