@@ -123,22 +123,27 @@ 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
126+ // check through each reference to see if we have source generators, and if any of them are required
127+ var hasOptionalGenerators = false ;
131128 var ( analyzerReferenceMap , callback ) = s_languageToAnalyzerReferenceMap [ language ] ;
132129 foreach ( var analyzerReference in isolatedReferences )
133130 {
134131 var generatorPresence = analyzerReferenceMap . GetValue ( analyzerReference , callback ) . Value ;
135132
133+ // we have at least one required generator, so no need to check the others
136134 if ( generatorPresence is SourceGeneratorPresence . ContainsRequiredSourceGenerators )
137135 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 ;
138141 }
139142
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 ;
142147 }
143148
144149 public ValueTask < ImmutableArray < SourceGeneratorIdentity > > GetSourceGeneratorIdentitiesAsync (
0 commit comments