Skip to content

Implement an internal generator for FiggleFonts class#41

Merged
drewnoakes merged 5 commits intomasterfrom
internal-figgle-font-generator
Jun 7, 2025
Merged

Implement an internal generator for FiggleFonts class#41
drewnoakes merged 5 commits intomasterfrom
internal-figgle-font-generator

Conversation

@jonathanou
Copy link
Copy Markdown
Collaborator

To make it easier to maintain more built-in fonts, #39 was created to auto-generate the font accessor properties using T4. However, as mentioned in the PR, T4 generation is Visual Studio-only and makes implementing #38 difficult.

As an alternative, we can create an internal-only source generator specifically for FiggleFonts class. We can continue to use Aliases.csv introduced in #39, and use the information to generate the property accessors for each built-in font.

In addition, with a source generator we can easily grab all the font files and parse their content into a FiggleFont. The parsed fonts can then be used to render a sample text to be included in the property's documentation.

Implementation

  • Create a new Figgle.Fonts.Generator project that is referenced as an analyzer by Figgle.Fonts.
  • Make FiggleFonts class partial and remove the existing hardcoded property accessors.
  • Update Figgle.Fonts.csproj to include Aliases.csv and all of the font files as AdditionalFiles so that our new source generator can access it.

Testing

  • Figgle.Fonts and its associated tests that accessed the property accessors builds.
  • Manually verified the generated code looks right and Visual Studio renders the documentation as expected:

image
image

@jonathanou jonathanou requested review from Copilot and drewnoakes June 7, 2025 15:59
Copy link
Copy Markdown

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

This PR implements an internal source generator to dynamically generate the font accessor properties in the FiggleFonts class, using the Aliases.csv file and bundled font files. Key changes include:

  • Converting the FiggleFonts class to a partial class and removing hard-coded property accessors.
  • Introducing the Figgle.Fonts.Generator project to generate font properties and sample documentation.
  • Updating project files and adding AdditionalFiles support for CSV and font files.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Figgle.sln Added a project reference for the internal generator.
Figgle.Fonts/FiggleFonts.cs Made the FiggleFonts class partial and removed hardcoded accessors.
Figgle.Fonts/Figgle.Fonts.csproj Configured AdditionalFiles and analyzer project references.
Figgle.Fonts/Aliases.csv Added CSV mappings for font names to member names.
Figgle.Fonts.Generator/FiggleFontGenerator.cs Added the source generator logic to generate font property accessors.
Figgle.Fonts.Generator/Figgle.Fonts.Generator.csproj Introduced the new generator project with necessary dependencies.

Comment thread Figgle.Fonts.Generator/FiggleFontGenerator.cs
Comment thread Figgle.Fonts.Generator/FiggleFontGenerator.cs
Copy link
Copy Markdown
Owner

@drewnoakes drewnoakes left a comment

Choose a reason for hiding this comment

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

Love this! Reckon the source generator will be helpful for other things too in future.

That doc popup 😍.

@drewnoakes drewnoakes merged commit bab4507 into master Jun 7, 2025
2 checks passed
@drewnoakes drewnoakes deleted the internal-figgle-font-generator branch June 7, 2025 16:58
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.

Generate sample output for each of the bundled fonts in XML doc comments

3 participants