Summary
The last outstanding piece of #181. Semantics.SourceGenerators/CodeGen/ holds the Roslyn-side infrastructure that has nothing to do with physical quantities. It is already shaped for extraction — a one-way dependency, nothing physics-specific, public where it needs to be — but it still lives in this repository, so a second project cannot use it without depending on ktsu.Semantics.
Until this lands, #181's definition of done is not met.
What moves
| File |
What it is |
CodeGen/GeneratorBase.cs |
IIncrementalGenerator base driven by N JSON metadata files supplied as AdditionalFiles; finds them, hands them to Generate, reports anything missing or malformed |
CodeGen/MetadataFile.cs |
MetadataFile / MetadataSet — deserialization, and FindLocation for pointing a diagnostic at a position in the metadata |
CodeGen/DiagnosticCatalog.cs |
Descriptor allocation under one prefix and category, plus the Report/ReportAt helpers |
CodeGen/CSharpKeywords.cs |
The generic C# vocabulary left over from splitting Emit |
Semantics.Test/Quantities/GeneratorHarness.cs |
The CSharpGeneratorDriver harness — supplies metadata the way MSBuild does, and can run a generator twice to check it reuses its output |
What stays: Models/, Metadata/, Generators/, SemanticsDiagnostics, SemanticsGenerator/SemanticsMultiFileGenerator, and the Semantics-specific half of Emit.
The decision this needs first
- (a) A new
ktsu-dev/SourceGeneratorToolkit repo — recommended. Keeps the Roslyn dependency and the analyzer-packaging rules (IsRoslynComponent, EnforceExtendedAnalyzerRules, the GetDependencyTargetPaths bundling target) out of ktsu.CodeBlocker, which ships 8 target frameworks down to netstandard2.0 and has one small dependency.
- (b) A second package in the
CodeBlocker repo (ktsu.CodeBlocker.SourceGenerators) — fewer repos, but couples CodeBlocker's release cadence to Roslyn's, and Roslyn moves fast enough that this repository already pins Microsoft.CodeAnalysis 5.9.
Notes for whoever picks it up
- The two Semantics base classes exist precisely to keep the toolkit consumer-agnostic:
SemanticsGenerator<T> binds the diagnostic catalogue and the file header in one place. A second consumer writes its own equivalent — that is the seam, and it should stay.
WriteFileHeader/WriteSourceFile take the copyright as a parameter rather than hard-coding it, so nothing about this repository leaks into the package.
- The harness carries the one piece of hard-won packaging knowledge worth not rediscovering: a project that references the generator as a plain library rather than as an analyzer must opt out of dependency bundling with
AdditionalProperties="BundleAnalyzerDependencies=false", or the bundled netstandard2.0 facades collide with the in-box types (CS0433 on ReadOnlySpan<T>, Vector4, and friends).
Semantics.SourceGenerators.csproj uses <Project Sdk="Microsoft.NET.Sdk"> rather than ktsu.Sdk. Worth deciding deliberately whether the new package follows suit.
Acceptance criteria
Context
Part of #181. #182 shaped this code for extraction; #187 removed the template half of it into ktsu.CodeBlocker 1.3.0. This is the remainder.
Summary
The last outstanding piece of #181.
Semantics.SourceGenerators/CodeGen/holds the Roslyn-side infrastructure that has nothing to do with physical quantities. It is already shaped for extraction — a one-way dependency, nothing physics-specific, public where it needs to be — but it still lives in this repository, so a second project cannot use it without depending onktsu.Semantics.Until this lands, #181's definition of done is not met.
What moves
CodeGen/GeneratorBase.csIIncrementalGeneratorbase driven by N JSON metadata files supplied asAdditionalFiles; finds them, hands them toGenerate, reports anything missing or malformedCodeGen/MetadataFile.csMetadataFile/MetadataSet— deserialization, andFindLocationfor pointing a diagnostic at a position in the metadataCodeGen/DiagnosticCatalog.csReport/ReportAthelpersCodeGen/CSharpKeywords.csEmitSemantics.Test/Quantities/GeneratorHarness.csCSharpGeneratorDriverharness — supplies metadata the way MSBuild does, and can run a generator twice to check it reuses its outputWhat stays:
Models/,Metadata/,Generators/,SemanticsDiagnostics,SemanticsGenerator/SemanticsMultiFileGenerator, and the Semantics-specific half ofEmit.The decision this needs first
ktsu-dev/SourceGeneratorToolkitrepo — recommended. Keeps the Roslyn dependency and the analyzer-packaging rules (IsRoslynComponent,EnforceExtendedAnalyzerRules, theGetDependencyTargetPathsbundling target) out ofktsu.CodeBlocker, which ships 8 target frameworks down tonetstandard2.0and has one small dependency.CodeBlockerrepo (ktsu.CodeBlocker.SourceGenerators) — fewer repos, but couples CodeBlocker's release cadence to Roslyn's, and Roslyn moves fast enough that this repository already pinsMicrosoft.CodeAnalysis5.9.Notes for whoever picks it up
SemanticsGenerator<T>binds the diagnostic catalogue and the file header in one place. A second consumer writes its own equivalent — that is the seam, and it should stay.WriteFileHeader/WriteSourceFiletake the copyright as a parameter rather than hard-coding it, so nothing about this repository leaks into the package.AdditionalProperties="BundleAnalyzerDependencies=false", or the bundlednetstandard2.0facades collide with the in-box types (CS0433 onReadOnlySpan<T>,Vector4, and friends).Semantics.SourceGenerators.csprojuses<Project Sdk="Microsoft.NET.Sdk">rather than ktsu.Sdk. Worth deciding deliberately whether the new package follows suit.Acceptance criteria
CodeGen/andGeneratorHarnesslive in the chosen package; this repository consumes them.Semantics.SourceGeneratorscontains onlyModels/,Metadata/,Generators/and the Semantics-specific bindings.Semantics.Quantities/Generated/unchanged (Generated files up to datestays green).Context
Part of #181. #182 shaped this code for extraction; #187 removed the template half of it into
ktsu.CodeBlocker1.3.0. This is the remainder.