Add multiple partial class definition support for embed font generator#43
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors attribute-aggregation logic into reusable extension methods and updates both source generators to support multiple partial class definitions for embedding Figgle fonts, avoiding filename conflicts.
- Extracted attribute collection and consolidation into
ForFiggleAttributeWithMetadataNameandConsolidateAttributeInfosByTypeSymbolextension methods. - Updated
RenderTextSourceGeneratorandEmbedFontSourceGeneratorto use the new extensions and merge multiple partial definitions. - Added unit tests in
EmbedFontSourceGeneratorTeststo verify behavior with multiple partial definitions and duplicate attributes.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Figgle.Generator/RenderTextSourceGenerator.cs | Replaced inline attribute aggregation with reusable extensions and adjusted the source-output loop for multiple partial definitions. |
| Figgle.Generator/IncrementalGeneratorExtensions.cs | Added new extension methods: ForFiggleAttributeWithMetadataName and ConsolidateAttributeInfosByTypeSymbol. |
| Figgle.Generator/IncrementalGeneratorContextExtensions.cs | Removed duplicate external-fonts provider now in IncrementalGeneratorExtensions. |
| Figgle.Generator/GenerationInfo.cs | Introduced generic GenerationInfo<TAttributeInfo> record struct. |
| Figgle.Generator/EmbedFontSourceGenerator.cs | Switched to consolidated attribute info, iterated multiple partials, and updated file naming. |
| Figgle.Generator.Tests/EmbedFontSourceGeneratorTests.cs | Added tests for duplicate attributes and member names across partial definitions. |
Comments suppressed due to low confidence (3)
Figgle.Generator/EmbedFontSourceGenerator.cs:131
- Using
returninside the loop will abort processing of all types after an invalid type; usecontinuehere to skip only the invalidtargetTypeand proceed with others.
return;
Figgle.Generator/EmbedFontSourceGenerator.cs:204
- Using
ToDisplayString(_fullyQualifiedFormat)for the generated filename may introduce characters invalid for file paths; consider usingtargetType.Nameor sanitizing the string.
"${targetType.ToDisplayString(_fullyQualifiedFormat)}.g.cs",
Figgle.Generator/RenderTextSourceGenerator.cs:128
- [nitpick] The variable name
embedFontInfoProvideris misleading inRenderTextSourceGenerator; consider renaming to something likerenderTextInfoProviderto reflect its purpose.
var embedFontInfoProvider = generationInfosProvider.Combine(externalFontsProvider);
| { | ||
| partial class DemoUsage | ||
| { | ||
| public static string FiggleString { get; } = @"_____________________________ _______ |
There was a problem hiding this comment.
NOTE: due to the use of HashSet when merging attributes, the order of the generated properties can be non-deterministic and was causing intermittent test failures.
To fix this, I switched to using ImmutableSortedSet and compared the items using their member names; thus the generated properties are always in alphabetical order so we must adjust our test code to match.
|
Been flat out today. Will review tomorrow 👍 |
drewnoakes
left a comment
There was a problem hiding this comment.
LGTM!
What's the best sequence to avoid conflicts between this and #42?
I think it might be easier if this PR went in first because git might be able to auto merge since it knows the new file is renamed? Let me know if this isn't the case, I can wait for your changes and re-apply mine. |
|
Tried the merge locally both ways and merging this first seems easier. |
Currently when multiple partial class definitions of the same class use
[EmbedFiggleFont], multiple generated files of the same filenames are produced and the compiler will error due conflicting filenames.This PR enables support for using
EmbedFiggleFonton multiple partial class definitions of the same class name and closes #35 .Implementation
RenderTextSourceGenerator(which does support multiple partial definitions) to an extension method for reuse.EmbedFontSourceGeneratorto use the new extension method.GenerationInfofrom attributes on class declarations.Testing
EmbedFontSourceGeneratorto check multiple partial definitions are working as expected.