Unify IndentedStringBuilder across MSTest source generators#9045
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR removes the duplicated IndentedStringBuilder implementation from MSTest.AotReflection.SourceGeneration by reusing the canonical helper from MSTest.SourceGeneration (via linked Compile items), ensuring both generators share the same indentation/block API and deterministic newline behavior.
Changes:
- Updated the canonical
IndentedStringBuilderto support the fluent API shape andBlock(...)pattern used by the AOT reflection generator. - Linked
IndentedStringBuilder.csand itsConstants.NewLinedependency intoMSTest.AotReflection.SourceGeneration. - Deleted the AOT reflection project’s duplicate helper and updated generator code to use the canonical helper’s namespace.
Show a summary per file
| File | Description |
|---|---|
| src/Analyzers/MSTest.SourceGeneration/Helpers/IndentedStringBuilder.cs | Makes the canonical helper fluent and adds Block(...) to match both generators’ call patterns while keeping deterministic newlines. |
| src/Analyzers/MSTest.AotReflection.SourceGeneration/MSTest.AotReflection.SourceGeneration.csproj | Links the canonical helper (and Constants.cs) into the AOT reflection generator project. |
| src/Analyzers/MSTest.AotReflection.SourceGeneration/Helpers/IndentedStringBuilder.cs | Removes the duplicate, AOT-specific helper implementation. |
| src/Analyzers/MSTest.AotReflection.SourceGeneration/Generators/MetadataRegistryEmitter.cs | Switches the generator to import the canonical helper namespace. |
Copilot's findings
- Files reviewed: 4/4 changed files
- Comments generated: 0
Evangelink
left a comment
There was a problem hiding this comment.
Note
🤖 Automated review by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.
| # | Dimension | Verdict |
|---|---|---|
| 15 | Code Structure | 🔵 1 NIT |
| 16 | Naming & Conventions | 🔵 1 NIT |
✅ 20/22 applicable dimensions clean (12 dimensions N/A for this change set).
-
AppendBlockis dead code with no callers — onlyBlockis used. Twointernalentry-points for the same operation is mildly confusing. (See inline comment.)
Overall assessment: The unification is well-executed. The file-linking approach (.csproj <Compile Link="..."/>) is the right mechanism, and switching from platform-specific StringBuilder.AppendLine() to the deterministic Constants.NewLine ("\n") is a genuine improvement for reproducible generator output. All behavioral semantics of the deleted AotReflection-specific IndentedStringBuilder are correctly preserved in the canonical version. The return-type promotion to IndentedStringBuilder (fluent style) is source-compatible with all existing void-discard call sites.
🤖 Automated content by GitHub Copilot. Posted via a maintainer's GitHub token, so it appears under their account — the account owner did not write or approve this content personally. Generated by the Expert Code Review (on PR ready) workflow. · 716.9 AIC · ⌖ 12.3 AIC · ◷
AppendBlock had no remaining call sites: every consumer in MetadataRegistryEmitter.cs goes through Block. Inline AppendBlock's body into Block to leave a single, unambiguous entry point on this internal helper. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fixes #8987
Summary
src/Analyzers/MSTest.SourceGeneration/Helpers/IndentedStringBuilder.csas the canonical helper.Constants.NewLinedependency) intoMSTest.AotReflection.SourceGeneration.Append/AppendLineandBlockstyle.Validation
dotnet build src\Analyzers\MSTest.SourceGeneration\MSTest.SourceGeneration.csproj -v minimal -m:1 -bl:{}dotnet build src\Analyzers\MSTest.AotReflection.SourceGeneration\MSTest.AotReflection.SourceGeneration.csproj -v minimal -m:1 -bl:{}dotnet build src\Analyzers\MSTest.Analyzers\MSTest.Analyzers.csproj -v minimal -m:1 -bl:{}dotnet test --project test\UnitTests\MSTest.SourceGeneration.UnitTests\MSTest.SourceGeneration.UnitTests.csproj --framework net8.0 --no-build -p:UsingDotNetTest=true -bl:{}dotnet test --project test\UnitTests\MSTest.AotReflection.SourceGeneration.UnitTests\MSTest.AotReflection.SourceGeneration.UnitTests.csproj --framework net8.0 --no-build -p:UsingDotNetTest=true -bl:{}dotnet test --project test\UnitTests\MSTest.Analyzers.UnitTests\MSTest.Analyzers.UnitTests.csproj --framework net8.0 --no-build -p:UsingDotNetTest=true -bl:{}