@@ -124,22 +124,26 @@ public async ValueTask<SourceGeneratorPresence> GetSourceGeneratorPresenceAsync(
124124 ( ) => assetProvider . GetAssetsArrayAsync < AnalyzerReference > ( projectId , checksumCollection , cancellationToken ) ,
125125 cancellationToken ) . ConfigureAwait ( false ) ;
126126
127- // if we don't have any analyzer references then we don't have any generators
128- if ( isolatedReferences . IsEmpty )
129- return SourceGeneratorPresence . NoSourceGenerators ;
130-
131- // see if any of the references have a required generator
132- var ( analyzerReferenceMap , callback ) = s_languageToAnalyzerReferenceMap [ language ] ;
127+ // check through each reference to see if we have source generators, and if any of them are required
128+ var hasOptionalGenerators = false ;
133129 foreach ( var analyzerReference in isolatedReferences )
134130 {
135131 var generatorPresence = analyzerReferenceMap . GetValue ( analyzerReference , callback ) . Value ;
136132
133+ // we have at least one required generator, so no need to check the others
137134 if ( generatorPresence is SourceGeneratorPresence . ContainsRequiredSourceGenerators )
138135 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 ;
139141 }
140142
141- // no required generators, all are optional
142- return SourceGeneratorPresence . OnlyOptionalSourceGenerators ;
143+ // we found no required generators, did we find any optional ones?
144+ return hasOptionalGenerators
145+ ? SourceGeneratorPresence . OnlyOptionalSourceGenerators
146+ : SourceGeneratorPresence . NoSourceGenerators ;
143147 }
144148
145149 public ValueTask < ImmutableArray < SourceGeneratorIdentity > > GetSourceGeneratorIdentitiesAsync (
0 commit comments