Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Commit

Permalink
Added support to treat all symbols at once.
Browse files Browse the repository at this point in the history
  • Loading branch information
jscarle committed Mar 6, 2024
1 parent df2be94 commit 24c2a2e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using System.Collections.Immutable;
using System.Text;
using AttributeSourceGenerator.Common;
using AttributeSourceGenerator.Models;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -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);
}

/// <summary>Adds the marker attribute source to the output.</summary>
Expand Down Expand Up @@ -129,12 +130,12 @@ private static Symbol Transform(GeneratorAttributeSyntaxContext context, Cancell
return symbol;
}

/// <summary>Generates source code for a given symbol.</summary>
/// <summary>Generates source for the given symbols.</summary>
/// <param name="context">The source production context.</param>
/// <param name="symbol">The symbol to generate source for.</param>
private void GenerateSourceForSymbol(SourceProductionContext context, Symbol symbol)
/// <param name="symbols">The symbols to generate source for.</param>
private void GenerateSourceForSymbols(SourceProductionContext context, ImmutableArray<Symbol> symbols)
{
var sources = _configuration.SourceGenerator(symbol);
var sources = _configuration.SourceGenerator(symbols);
foreach (var source in sources)
context.AddSource($"{source.Name}.g.cs", source.Text);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace AttributeSourceGenerator;
using System.Collections.Immutable;

namespace AttributeSourceGenerator;

/// <summary>Defines the configuration for an incremental attribute generator.</summary>
public sealed class AttributeIncrementalGeneratorConfiguration
Expand All @@ -13,7 +15,7 @@ public sealed class AttributeIncrementalGeneratorConfiguration
public FilterType SymbolFilter { get; init; } = FilterType.All;

/// <summary>The function that generates the source code for the attribute.</summary>
public required Func<Symbol, IEnumerable<Source>> SourceGenerator { get; init; }
public required Func<ImmutableArray<Symbol>, IEnumerable<Source>> SourceGenerator { get; init; }

/// <summary>Initializes a new instance of the <see cref="AttributeIncrementalGeneratorConfiguration" /> class</summary>
public AttributeIncrementalGeneratorConfiguration()
Expand Down
6 changes: 3 additions & 3 deletions src/AttributeSourceGenerator/AttributeSourceGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<RootNamespace>AttributeSourceGenerator</RootNamespace>
<LangVersion>latest</LangVersion>
<Version>8.0.3</Version>
<Version>8.0.4</Version>
<Title>AttributeSourceGenerator</Title>
<Authors>Jean-Sebastien Carle</Authors>
<Description>A simple attribute-based Roslyn incremental source generator base class for .NET.</Description>
Expand All @@ -18,8 +18,8 @@
<RepositoryUrl>https://github.com/jscarle/AttributeSourceGenerator</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>attribute source-generator attribute-based source-generators</PackageTags>
<AssemblyVersion>8.0.3.0</AssemblyVersion>
<FileVersion>8.0.3.0</FileVersion>
<AssemblyVersion>8.0.4.0</AssemblyVersion>
<FileVersion>8.0.4.0</FileVersion>
<NeutralLanguage>en-US</NeutralLanguage>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
Expand Down

0 comments on commit 24c2a2e

Please sign in to comment.