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> SourceGenerator { get; init; } /// Initializes a new instance of the class public AttributeIncrementalGeneratorConfiguration() diff --git a/src/AttributeSourceGenerator/AttributeSourceGenerator.csproj b/src/AttributeSourceGenerator/AttributeSourceGenerator.csproj index bf3dbb9..73fc851 100644 --- a/src/AttributeSourceGenerator/AttributeSourceGenerator.csproj +++ b/src/AttributeSourceGenerator/AttributeSourceGenerator.csproj @@ -6,7 +6,7 @@ enable AttributeSourceGenerator latest - 8.0.3 + 8.0.4 AttributeSourceGenerator Jean-Sebastien Carle A simple attribute-based Roslyn incremental source generator base class for .NET. @@ -18,8 +18,8 @@ https://github.com/jscarle/AttributeSourceGenerator git attribute source-generator attribute-based source-generators - 8.0.3.0 - 8.0.3.0 + 8.0.4.0 + 8.0.4.0 en-US true snupkg