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