@@ -123,22 +123,27 @@ public async ValueTask<SourceGeneratorPresence> GetSourceGeneratorPresenceAsync(
123
123
( ) => assetProvider . GetAssetsArrayAsync < AnalyzerReference > ( projectId , checksumCollection , cancellationToken ) ,
124
124
cancellationToken ) . ConfigureAwait ( false ) ;
125
125
126
- // if we don't have any analyzer references then we don't have any generators
127
- if ( isolatedReferences . IsEmpty )
128
- return SourceGeneratorPresence . NoSourceGenerators ;
129
-
130
- // see if any of the references have a required generator
126
+ // check through each reference to see if we have source generators, and if any of them are required
127
+ var hasOptionalGenerators = false ;
131
128
var ( analyzerReferenceMap , callback ) = s_languageToAnalyzerReferenceMap [ language ] ;
132
129
foreach ( var analyzerReference in isolatedReferences )
133
130
{
134
131
var generatorPresence = analyzerReferenceMap . GetValue ( analyzerReference , callback ) . Value ;
135
132
133
+ // we have at least one required generator, so no need to check the others
136
134
if ( generatorPresence is SourceGeneratorPresence . ContainsRequiredSourceGenerators )
137
135
return SourceGeneratorPresence . ContainsRequiredSourceGenerators ;
136
+
137
+ // if we have optional generators, make a note of it,
138
+ // but we still need to scan the rest to see if they have any required ones
139
+ if ( generatorPresence is SourceGeneratorPresence . OnlyOptionalSourceGenerators )
140
+ hasOptionalGenerators = true ;
138
141
}
139
142
140
- // no required generators, all are optional
141
- return SourceGeneratorPresence . OnlyOptionalSourceGenerators ;
143
+ // we found no required generators, did we find any optional ones?
144
+ return hasOptionalGenerators
145
+ ? SourceGeneratorPresence . OnlyOptionalSourceGenerators
146
+ : SourceGeneratorPresence . NoSourceGenerators ;
142
147
}
143
148
144
149
public ValueTask < ImmutableArray < SourceGeneratorIdentity > > GetSourceGeneratorIdentitiesAsync (
0 commit comments