Skip to content

Replace ISourceGenerator with IIncrementalGenerator (#11302)#12271

Draft
msynk wants to merge 1 commit intobitfoundation:developfrom
msynk:11302-sourcegenerators-incremental-generators
Draft

Replace ISourceGenerator with IIncrementalGenerator (#11302)#12271
msynk wants to merge 1 commit intobitfoundation:developfrom
msynk:11302-sourcegenerators-incremental-generators

Conversation

@msynk
Copy link
Copy Markdown
Member

@msynk msynk commented Apr 22, 2026

closes #11302

@msynk msynk requested review from Copilot and yasmoradi April 22, 2026 12:54
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 64807f54-3869-4a57-81d5-9bb4c54c2734

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates the Bit source generators from legacy ISourceGenerator/syntax receivers to Roslyn incremental generators to reduce redundant work during builds and improve IDE responsiveness (per #11302).

Changes:

  • Replaced syntax receivers with IIncrementalGenerator pipelines for HttpClientProxy, AutoInject, and SetParameters generators.
  • Introduced flat/serializable record-struct models (ControllerEntry, BitProperty, BlazorParameter, AutoInjectMember) to support incremental caching.
  • Added IsExternalInit polyfills to enable record struct usage while targeting netstandard2.0.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/SourceGenerators/Bit.SourceGenerators/IsExternalInit.cs Adds IsExternalInit polyfill for netstandard2.0 record/init support.
src/SourceGenerators/Bit.SourceGenerators/HttpClientProxy/IController.cs Removes legacy mutable controller model used by the syntax receiver.
src/SourceGenerators/Bit.SourceGenerators/HttpClientProxy/HttpClientProxySyntaxReceiver.cs Removes legacy ISyntaxContextReceiver implementation.
src/SourceGenerators/Bit.SourceGenerators/HttpClientProxy/HttpClientProxySourceGenerator.cs Reworks HttpClientProxy generation as an incremental generator; uses encoded action data for value-based equality.
src/SourceGenerators/Bit.SourceGenerators/HttpClientProxy/ControllerEntry.cs Adds flat, equatable controller model for incremental transform/output.
src/SourceGenerators/Bit.SourceGenerators/HttpClientProxy/ControllerAction.cs Removes legacy mutable action model.
src/SourceGenerators/Bit.SourceGenerators/HttpClientProxy/ActionParameter.cs Removes legacy mutable parameter model.
src/SourceGenerators/Bit.SourceGenerators/Blazor/BlazorSetParametersSourceGenerator.cs Replaces receiver-based SetParameters generator with incremental attribute-driven pipeline.
src/SourceGenerators/Bit.SourceGenerators/Blazor/BlazorParameterPropertySyntaxReceiver.cs Removes legacy receiver.
src/SourceGenerators/Bit.SourceGenerators/Blazor/BitProperty.cs Replaces Roslyn-symbol-based class with flat record struct used for caching.
src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectSyntaxReceiver.cs Removes legacy receiver.
src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectSourceGenerator.cs Reworks AutoInject generation as incremental; introduces direct/derived entry modeling and encoded base-member caching.
src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectRazorComponentHandler.cs Updates handler to accept serialized member/type info instead of Roslyn symbols.
src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectNormalClassHandler.cs Updates handler to accept serialized member/type info and preserve nullable default behavior.
src/SourceGenerators/Bit.SourceGenerators/AutoInject/AutoInjectMember.cs Adds serialized member model for incremental processing.
src/BlazorUI/Bit.BlazorUI.SourceGenerators/IsExternalInit.cs Adds IsExternalInit polyfill for netstandard2.0 record/init support.
src/BlazorUI/Bit.BlazorUI.SourceGenerators/Component/ComponentSyntaxContextReceiver.cs Removes legacy receiver.
src/BlazorUI/Bit.BlazorUI.SourceGenerators/Component/ComponentSourceGenerator.cs Reworks component SetParameters generator as an incremental generator; captures parameter metadata as strings/bools.
src/BlazorUI/Bit.BlazorUI.SourceGenerators/Component/BlazorParameter.cs Replaces Roslyn-symbol-based model with flat record struct.
src/BlazorUI/Bit.BlazorUI.SourceGenerators/AutoInject/AutoInjectSyntaxReceiver.cs Removes legacy receiver.
src/BlazorUI/Bit.BlazorUI.SourceGenerators/AutoInject/AutoInjectSourceGenerator.cs Reworks AutoInject generation as incremental for BlazorUI generators.
src/BlazorUI/Bit.BlazorUI.SourceGenerators/AutoInject/AutoInjectRazorComponentHandler.cs Updates handler to accept serialized member/type info instead of Roslyn symbols.
src/BlazorUI/Bit.BlazorUI.SourceGenerators/AutoInject/AutoInjectNormalClassHandler.cs Updates handler to accept serialized member/type info instead of Roslyn symbols.
src/BlazorUI/Bit.BlazorUI.SourceGenerators/AutoInject/AutoInjectMember.cs Adds serialized member model for incremental processing.

Comment on lines +180 to +183
if (!first.IsPartial)
{
spc.ReportDiagnostic(Diagnostic.Create(NonPartialClassError, Location.None, first.ClassName));
continue;
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-partial class diagnostics are reported with Location.None, which makes the error hard to trace back to the offending class. Use the declaring syntax reference location (e.g., the first ClassDeclarationSyntax from DeclaringSyntaxReferences) so the diagnostic is placed on the class declaration.

Copilot uses AI. Check for mistakes.
Comment on lines +206 to +209
if (!entry.IsPartial)
{
context.ReportDiagnostic(Diagnostic.Create(NonPartialClassError, classDeclarationSyntax.GetLocation(), @class.Name));
return false;
spc.ReportDiagnostic(Diagnostic.Create(NonPartialClassError, Location.None, entry.ClassName));
continue;
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-partial class diagnostics are reported with Location.None here too; consider reporting on the class declaration location (from DeclaringSyntaxReferences) so users can navigate directly to the source of the error.

Copilot uses AI. Check for mistakes.
Comment on lines +175 to +178
if (!first.IsPartial)
{
spc.ReportDiagnostic(Diagnostic.Create(NonPartialClassError, Location.None, first.ClassName));
continue;
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diagnostic for non-partial classes is created with Location.None, which reduces IDE usability. Prefer attaching the diagnostic to the class declaration location (from DeclaringSyntaxReferences) so the error highlights the correct code.

Copilot uses AI. Check for mistakes.
Comment on lines +201 to +204
if (!entry.IsPartial)
{
spc.ReportDiagnostic(Diagnostic.Create(NonPartialClassError, Location.None, entry.ClassName));
continue;
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: reporting this diagnostic with Location.None makes it hard to find the offending derived class. Use the class declaration syntax location where possible.

Copilot uses AI. Check for mistakes.
@Kyemate
Copy link
Copy Markdown
Contributor

Kyemate commented Apr 23, 2026

Nice migration overall👍 I looked at the pr briefly with the help of ai and found two things that stood out and could be improved.

First, it would be good to reduce the current .Collect() / final grouping pattern where possible. Even though this is using incremental APIs, batching a lot of data before generation limits the actual benefits of incremental generators.

Second, HttpClientProxy would likely benefit from being generated per controller instead of as one combined output. As it is now, a small API change can trigger regeneration of the entire proxy, whereas per-controller generation would give much better granularity and reduce excessive regeneration.

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.

Migrate Bit.SourceGenerators to Incremental Generators

3 participants