-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Migrate code generation from StringBuilder to Scriban templates (v1.0.5-beta) #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add Scriban templating support to the source generator project. Changes: - Add Scriban 6.5.0 package with source inclusion - Add Microsoft.CSharp 4.7.0 for dynamic binding support - Create Templates/ and OutputGenerators/ folder structure - Add TemplateHelper.cs for loading templates from embedded resources - Add TemplateConstants.cs for template resource paths - Configure .csproj to embed .scriban files as resources This establishes the foundation for migrating from StringBuilder-based code generation to maintainable Scriban templates. Phase 1 of Scriban migration plan - infrastructure setup complete. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Add Scriban 6.5.0 and Microsoft.CSharp 4.7.0 dependencies - Create TemplateHelper with caching and improved error messages (ChatGPT feedback) - Create TemplateConstants for template resource paths - Migrate InterceptsLocationAttribute, DecoratorKeys, and DecoratorFactory to Scriban templates - Create CommonSources with individual generator methods for clean separation - Update InterceptorEmitter to use CommonSources for template rendering - All 49 tests passing This is Phase 2 of the Scriban migration. Common helper code now uses templates instead of StringBuilder. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
This commit migrates the code generation infrastructure from StringBuilder
to Scriban 6.5.0 templates for improved maintainability and readability.
## Changes
### Template-based Code Generation
- Unified template generates all interceptor code for 8 registration kinds
- Conditional logic handles variations (keyed, factory, instance, two-type-params)
- Template caching with ConcurrentDictionary<string, Template> for performance
- Strongly-typed RegistrationModel (readonly record struct) for zero-boxing
### Code Cleanup
- Removed 570+ lines of StringBuilder emission code
- Simplified InterceptorEmitter.cs from 440+ lines to ~70 lines
- Removed individual template files (Common/*)
- Single unified template: DecoWeaverInterceptors.scriban
- Cleaned up unused TemplateConstants
### Comment Reduction
- Removed generic "Register X" comments
- Kept only valuable WHY comments:
- "Create nested key to avoid circular resolution"
- "Compose decorators (innermost to outermost)"
### Dependencies
- Added Scriban 6.5.0
- Added Microsoft.CSharp 4.7.0 (for Scriban's dynamic features)
### Version and Documentation
- Bumped version to 1.0.5-beta
- Updated changelog and release notes
- All 49 tests passing with updated snapshots
## Technical Details
- Template resource format: Templates.{FileName}.scriban embedded in assembly
- No functional changes - generated code is equivalent (except comment reduction)
- Build performance unchanged - template compilation is one-time cost with caching
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
|
@codex review |
There was a problem hiding this comment.
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 migrates the code generation infrastructure from StringBuilder to Scriban 6.5.0 templates, simplifying the codebase by removing 570+ lines of manual string building code while maintaining functional equivalence. The refactoring consolidates eight different registration patterns into a single unified template with conditional logic.
Key changes:
- Replaced StringBuilder-based code generation with Scriban template system featuring caching and strongly-typed models
- Reduced generated code comments to retain only meaningful explanations of non-obvious logic
- Updated package versions including Scriban 6.5.0, Microsoft.CSharp 4.7.0, and Polyfill 9.0.3
Reviewed Changes
Copilot reviewed 51 out of 51 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/LayeredCraft.DecoWeaver.Generators/Templates/DecoWeaverInterceptors.scriban |
New unified Scriban template generating all interceptor code patterns |
src/LayeredCraft.DecoWeaver.Generators/OutputGenerators/DecoWeaverInterceptorsSources.cs |
New helper for template model creation and rendering coordination |
src/LayeredCraft.DecoWeaver.Generators/Emit/TemplateHelper.cs |
New template loading/caching infrastructure with concurrent dictionary |
src/LayeredCraft.DecoWeaver.Generators/Emit/TemplateConstants.cs |
New constants defining template resource paths |
src/LayeredCraft.DecoWeaver.Generators/Emit/InterceptorEmitter.cs |
Simplified from 440+ to ~70 lines by delegating to template system |
src/LayeredCraft.DecoWeaver.Generators/LayeredCraft.DecoWeaver.Generators.csproj |
Added Scriban and Microsoft.CSharp dependencies, embedded template resources |
src/LayeredCraft.DecoWeaver.Attributes/LayeredCraft.DecoWeaver.Attributes.csproj |
Updated Polyfill from 9.0.2 to 9.0.3 |
Directory.Build.props |
Version bump to 1.0.5-beta |
releasenotes.props |
Added release notes for 1.0.5-beta |
docs/changelog.md |
Documented migration changes and technical details |
test/LayeredCraft.DecoWeaver.Generator.Tests/Snapshots/*.verified.cs |
Updated snapshots reflecting comment removal in generated code |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/LayeredCraft.DecoWeaver.Generators/LayeredCraft.DecoWeaver.Generators.csproj
Show resolved
Hide resolved
j-d-ha
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I think the template helps readability a lot.
Summary
This PR migrates the code generation infrastructure from StringBuilder to Scriban 6.5.0 templates for improved maintainability and readability. Version bumped to 1.0.5-beta.
What's Changed
🎨 Template-based Code Generation
ConcurrentDictionary<string, Template>for performanceRegistrationModel(readonly record struct) for zero-boxing overhead🧹 Code Cleanup
InterceptorEmitter.csfrom 440+ lines to ~70 linesCommon/InterceptsLocationAttribute,DecoratorKeys,DecoratorFactory)DecoWeaverInterceptors.scribanTemplateConstants📝 Comment Reduction
📦 Dependencies
Scriban 6.5.0Microsoft.CSharp 4.7.0(for Scriban's dynamic features)📚 Documentation
Directory.Build.propsto version 1.0.5-betadocs/changelog.mdwith comprehensive changesreleasenotes.propswith new release notesTechnical Details
Templates.{FileName}.scribanembedded in assembly{{-syntax for whitespace controlTest Results
Breaking Changes
None - this is a purely internal refactoring. Generated code is functionally equivalent.
🤖 Generated with Claude Code