diff --git a/src/AttributeSourceGenerator/AttributeIncrementalGeneratorBase.cs b/src/AttributeSourceGenerator/AttributeIncrementalGeneratorBase.cs
index eeaaf84..3c240c2 100644
--- a/src/AttributeSourceGenerator/AttributeIncrementalGeneratorBase.cs
+++ b/src/AttributeSourceGenerator/AttributeIncrementalGeneratorBase.cs
@@ -1,4 +1,5 @@
-using System.Text;
+using System.Collections.Immutable;
+using System.Text;
using AttributeSourceGenerator.Common;
using AttributeSourceGenerator.Models;
using Microsoft.CodeAnalysis;
@@ -36,8 +37,8 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
{
context.RegisterPostInitializationOutput(AddMarkerAttributeSource);
- var syntaxProvider = context.SyntaxProvider.ForAttributeWithMetadataName(_configuration.MarkerAttributeName, Filter, Transform);
- context.RegisterSourceOutput(syntaxProvider, GenerateSourceForSymbol);
+ var syntaxProvider = context.SyntaxProvider.ForAttributeWithMetadataName(_configuration.MarkerAttributeName, Filter, Transform).Collect();
+ context.RegisterSourceOutput(syntaxProvider, GenerateSourceForSymbols);
}
/// Adds the marker attribute source to the output.
@@ -129,12 +130,12 @@ private static Symbol Transform(GeneratorAttributeSyntaxContext context, Cancell
return symbol;
}
- /// Generates source code for a given symbol.
+ /// Generates source for the given symbols.
/// The source production context.
- /// The symbol to generate source for.
- private void GenerateSourceForSymbol(SourceProductionContext context, Symbol symbol)
+ /// The symbols to generate source for.
+ private void GenerateSourceForSymbols(SourceProductionContext context, ImmutableArray symbols)
{
- var sources = _configuration.SourceGenerator(symbol);
+ var sources = _configuration.SourceGenerator(symbols);
foreach (var source in sources)
context.AddSource($"{source.Name}.g.cs", source.Text);
}
diff --git a/src/AttributeSourceGenerator/AttributeIncrementalGeneratorConfiguration.cs b/src/AttributeSourceGenerator/AttributeIncrementalGeneratorConfiguration.cs
index 06425cf..dd1b37a 100644
--- a/src/AttributeSourceGenerator/AttributeIncrementalGeneratorConfiguration.cs
+++ b/src/AttributeSourceGenerator/AttributeIncrementalGeneratorConfiguration.cs
@@ -1,4 +1,6 @@
-namespace AttributeSourceGenerator;
+using System.Collections.Immutable;
+
+namespace AttributeSourceGenerator;
/// Defines the configuration for an incremental attribute generator.
public sealed class AttributeIncrementalGeneratorConfiguration
@@ -13,7 +15,7 @@ public sealed class AttributeIncrementalGeneratorConfiguration
public FilterType SymbolFilter { get; init; } = FilterType.All;
/// The function that generates the source code for the attribute.
- public required Func> SourceGenerator { get; init; }
+ public required Func, IEnumerable