@@ -123,22 +123,26 @@ public async ValueTask<SourceGeneratorPresence> GetSourceGeneratorPresenceAsync(
123123 ( ) => assetProvider . GetAssetsArrayAsync < AnalyzerReference > ( projectId , checksumCollection , cancellationToken ) ,
124124 cancellationToken ) . ConfigureAwait ( false ) ;
125125
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 ;
132128 foreach ( var analyzerReference in isolatedReferences )
133129 {
134130 var generatorPresence = analyzerReferenceMap . GetValue ( analyzerReference , callback ) . Value ;
135131
132+ // we have at least one required generator, so no need to check the others
136133 if ( generatorPresence is SourceGeneratorPresence . ContainsRequiredSourceGenerators )
137134 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 ;
138140 }
139141
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 ;
142146 }
143147
144148 public ValueTask < ImmutableArray < SourceGeneratorIdentity > > GetSourceGeneratorIdentitiesAsync (
0 commit comments