Skip to content

Fix: multiple AutoGenerateBuilder(typeof) classes produce no output#78

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-autogeneratebuilder-issue
Draft

Fix: multiple AutoGenerateBuilder(typeof) classes produce no output#78
Copilot wants to merge 3 commits into
mainfrom
copilot/fix-autogeneratebuilder-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 29, 2026

When two or more [AutoGenerateBuilder(typeof(T))] classes reference external/third-party types, the incremental source generator silently produces no output for any of them.

Changes

FluentBuilderSourceGenerator — fix incremental generator pipeline

  • Remove shared mutable diagnostics list captured in lambda closures — a violation of incremental generator purity requirements that caused stale/duplicate diagnostics across incremental compilations
  • Pipeline diagnostics through the transform result as (FluentData Data, Diagnostic? Diagnostic) tuple, reported via a dedicated RegisterSourceOutput
  • Use IsSyntaxTarget as the predicate (syntax-only, no modifier check) and move full CheckSyntaxNode validation into the transform so diagnostics are never silently dropped for filtered-out nodes

AutoGenerateBuilderSyntaxReceiver — fix silent pipeline abort

  • HandleSyntaxNode no longer throws InvalidOperationException when TryGet returns false (e.g. builder class missing partial). Previously, this exception could abort the entire SyntaxProvider batch, causing all builders in the compilation to generate nothing
  • Add IsSyntaxTarget() — fast syntax-only candidate filter for use as the pipeline predicate

FluentData — fix incremental caching

  • Implement IEquatable<FluentData> with proper List<string> content equality. The struct contained a List<string> Usings field; without this, Roslyn's equality check always returned false (different list references), breaking the incremental cache

FluentBuilderClassesGenerator — defensive null guard

  • Skip FluentData items with null/empty MetadataName in GetClassSymbols to safely handle any default-valued structs that reach the generator

Example scenario now working

// Both A and B are third-party DTOs (from NuGet, not in project source)
[AutoGenerateBuilder(typeof(A))]
public partial class ABuilder { }

[AutoGenerateBuilder(typeof(B))]
public partial class BBuilder { }

Previously: neither ABuilder.g.cs nor BBuilder.g.cs was generated.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits March 29, 2026 17:42
Copilot AI changed the title [WIP] Fix AutoGenerateBuilder not generating classes for multiple definitions Fix: multiple AutoGenerateBuilder(typeof) classes produce no output Mar 29, 2026
Copilot AI requested a review from StefH March 29, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AutoGenerateBuilder for type doesn't generate classess

2 participants