Skip to content

feat(pipeline): RegisterCollectedEmitter + IsTypeAccessible + IsToggleEnabled - #91

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/pipeline-helpers
May 4, 2026
Merged

feat(pipeline): RegisterCollectedEmitter + IsTypeAccessible + IsToggleEnabled#91
github-actions[bot] merged 1 commit into
mainfrom
feat/pipeline-helpers

Conversation

@ANcpLua

@ANcpLua ANcpLua commented May 4, 2026

Copy link
Copy Markdown
Owner

Summary

Promotes three patterns observed across consuming generator codebases (qyl, MAF agent-framework, LoggerMessageNPlus2) into shared by-the-book helpers, collapsing typical per-concern generator boilerplate to a single declarative line.

  • IncrementalValuesProviderExtensions.RegisterCollectedEmitter<T> — canonical "collect → gate → exception-safe emit → AddSource" pipeline, with a FileWithName overload and a (filename, string emitter) overload.
  • CompilationExtensions.IsTypeAccessible — projects IncrementalValueProvider<Compilation> to a value-equatable bool in one call. Avoids the textbook anti-pattern of combining the non-equatable Compilation directly into a downstream stage (which thrashes the generator cache on every keystroke).
  • AnalyzerConfigOptionsProviderExtensions.IsToggleEnabled — same shape for an MSBuild boolean toggle, with defaultValue defaulting to true.

Why

Three independent generator codebases reinvented the same dual-gate + collect + emit boilerplate locally. Surfacing it once in Roslyn.Utilities lets each per-concern generator become a thin declaration of inputs/gates/outputs:

var runtimeAvailable = context.CompilationProvider.IsTypeAccessible("My.Runtime.Marker");
var enabled = context.AnalyzerConfigOptionsProvider.IsToggleEnabled("MyFeature");
var gate = runtimeAvailable.Combine(enabled).Select(static (p, _) => p.Left && p.Right);

callSites.RegisterCollectedEmitter(context, gate, "My.g.cs", MyEmitter.Emit);

Test plan

  • dotnet build clean (zero warnings, TreatWarningsAsErrors enforces cref regression — no CS0419)
  • Testing.Tests 23/23 pass
  • No new dependencies; only composes existing helpers (CollectAsEquatableArray, Combine, SelectAndReportExceptions, AddSource, HasAccessibleTypeWithMetadataName, GetGlobalBoolOrDefault)

🤖 Generated with Claude Code

…oggleEnabled

Promotes three patterns observed across consuming generator codebases
(qyl, MAF, LoggerMessageNPlus2) into shared, by-the-book helpers:

- IncrementalValuesProviderExtensions.RegisterCollectedEmitter<T> — the
  canonical "collect → gate → exception-safe emit → AddSource" pipeline,
  with a FileWithName overload and a (filename, string emitter) overload.

- CompilationExtensions.IsTypeAccessible — projects an
  IncrementalValueProvider<Compilation> to a value-equatable bool in one
  call. Avoids the textbook anti-pattern of combining the non-equatable
  Compilation directly into a downstream stage, which thrashes the
  generator cache on every keystroke.

- AnalyzerConfigOptionsProviderExtensions.IsToggleEnabled — same shape
  for an MSBuild boolean toggle, with a defaultValue (defaults to true).

Together these collapse the typical per-concern generator boilerplate
("dual gate + collect + emit") to a single declarative line.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 4, 2026 18:32
@github-actions
github-actions Bot enabled auto-merge (squash) May 4, 2026 18:32
@github-actions
github-actions Bot merged commit 823e30d into main May 4, 2026
12 of 13 checks passed
@coderabbitai

coderabbitai Bot commented May 4, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5e285590-d628-438b-89f2-70c7d414f703

📥 Commits

Reviewing files that changed from the base of the PR and between 5306045 and 4caf1d2.

📒 Files selected for processing (3)
  • src/ANcpLua.Roslyn.Utilities/AnalyzerConfigOptionsProviderExtensions.cs
  • src/ANcpLua.Roslyn.Utilities/CompilationExtensions.cs
  • src/ANcpLua.Roslyn.Utilities/IncrementalValuesProviderExtensions.cs

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting


Summary by CodeRabbit

  • New Features
    • Enhanced source generation utilities with improved configuration option processing capabilities.
    • Added type accessibility verification for compilation analysis.
    • Introduced standardized incremental generator registration patterns with exception handling and gating support.

Walkthrough

Three extension methods added to support incremental generator pipelines: IsToggleEnabled projects MSBuild analyzer options into boolean gates; IsTypeAccessible projects compilations into type-accessibility checks; RegisterCollectedEmitter registers standardized collection-combine-transform-emit pipelines with exception handling and gating support.

Changes

Incremental Generator Helper Extensions

Layer / File(s) Summary
Gating & Selection Helpers
src/ANcpLua.Roslyn.Utilities/AnalyzerConfigOptionsProviderExtensions.cs, src/ANcpLua.Roslyn.Utilities/CompilationExtensions.cs
IsToggleEnabled projects config options into parsed boolean gates; IsTypeAccessible projects compilations into type-accessible checks via existing HasAccessibleTypeWithMetadataName.
Collection & Emission Pipeline
src/ANcpLua.Roslyn.Utilities/IncrementalValuesProviderExtensions.cs
Two RegisterCollectedEmitter overloads wire collected-and-gated pipelines: array collection, gate combination, exception-wrapped transformation, and source emission. Convenience overload converts string-returning emitters into FileWithName.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes


Review rate limit: 4/5 reviews remaining, refill in 12 minutes.

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR promotes common incremental-generator pipeline patterns into shared helpers in ANcpLua.Roslyn.Utilities, reducing repeated boilerplate in consuming generators while preserving incremental caching behavior (projecting non-equatable Roslyn inputs into value-equatable boolean “gates”, and standardizing a collect+gate+emit pipeline).

Changes:

  • Add IncrementalValuesProviderExtensions.RegisterCollectedEmitter<T> overloads to standardize “collect → gate → exception-safe emit → AddSource” for single-file generation.
  • Add CompilationExtensions.IsTypeAccessible to project CompilationProvider into a value-equatable boolean gate based on accessible type presence.
  • Add AnalyzerConfigOptionsProviderExtensions.IsToggleEnabled to project config options into a value-equatable boolean gate based on an MSBuild boolean property with a default.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/ANcpLua.Roslyn.Utilities/IncrementalValuesProviderExtensions.cs Adds RegisterCollectedEmitter<T> helpers composing existing pipeline primitives (collect/combine/exception reporting/add-source).
src/ANcpLua.Roslyn.Utilities/CompilationExtensions.cs Adds IsTypeAccessible to convert CompilationProvider into a boolean gate using existing accessibility checks.
src/ANcpLua.Roslyn.Utilities/AnalyzerConfigOptionsProviderExtensions.cs Adds IsToggleEnabled to convert AnalyzerConfigOptionsProvider into a boolean gate using existing MSBuild boolean parsing helpers.

@ANcpLua
ANcpLua deleted the feat/pipeline-helpers branch May 5, 2026 13:22
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.

2 participants