Skip to content

Fix generated code compilation errors when any description contains newlines - #193

Merged
Tyrrrz merged 6 commits into
primefrom
copilot/fix-multiline-description-issue
Aug 31, 2026
Merged

Tyrrrz merged 6 commits into
primefrom
copilot/fix-multiline-description-issue

Conversation

Copilot AI commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Multiline Description values on [Command], [CommandOption], or [CommandParameter] produced invalid generated code (*.Descriptor.g.cs), failing with CS1010: Newline in constant. The generator's string escaping only handled backslashes and quotes, leaving embedded newlines as literal line breaks inside the emitted string literal.

  • CliFx.Generators/Utils/CSharp.cs: replaced the hand-rolled Escape/Encode logic with Microsoft.CodeAnalysis.CSharp.SymbolDisplay.FormatLiteral, which correctly escapes newlines and all other special characters when producing string literals. Removed the now-unused Escape method.
  • CliFx.Tests/HelpSpecs.cs: added a regression test compiling a command with multiline Description (via raw string literal and \n) on [Command], [CommandOption], and [CommandParameter], asserting the help output renders correctly.

Example that now compiles correctly:

[Command("example", Description = """
    here is line 1

    here is line 2
    """)]
public partial class ExampleCommand : ICommand { ... }

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix multiline description handling in command generation Fix generated code containing raw newlines in string literals for multiline Description values Aug 31, 2026
Copilot AI requested a review from Tyrrrz August 31, 2026 14:43
Comment thread CliFx.Tests/HelpSpecs.cs Outdated
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copilot AI requested a review from Tyrrrz August 31, 2026 14:51
@Tyrrrz
Tyrrrz marked this pull request as ready for review August 31, 2026 15:02
Copilot AI lite review requested due to automatic review settings August 31, 2026 15:02
@codecov

codecov Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.50%. Comparing base (c43c4d1) to head (982c8d8).

Additional details and impacted files
@@            Coverage Diff             @@
##            prime     #193      +/-   ##
==========================================
- Coverage   90.50%   90.50%   -0.01%     
==========================================
  Files          66       66              
  Lines        2339     2338       -1     
  Branches      282      282              
==========================================
- Hits         2117     2116       -1     
  Misses        140      140              
  Partials       82       82              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The generator’s Encode(char?) still emits unescaped char literals, which can produce invalid generated C# for certain short-name values.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes a source-generator bug where multiline Description values (on [Command], [CommandOption], and [CommandParameter]) could produce uncompilable generated descriptor code due to raw newline characters in emitted string literals.

Changes:

  • Switched generator string literal encoding to Roslyn’s SymbolDisplay.FormatLiteral to correctly escape newlines and other special characters.
  • Added a regression test that compiles commands with multiline descriptions and validates the resulting help output contains the expected text.
File summaries
File Description
CliFx.Generators/Utils/CSharp.cs Updates string encoding in generated code to use Roslyn literal formatting for correct escaping.
CliFx.Tests/HelpSpecs.cs Adds a regression test covering multiline descriptions on command/option/parameter metadata.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread CliFx.Generators/Utils/CSharp.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment thread CliFx.Generators/Utils/CSharp.cs Outdated
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copilot AI requested a review from Tyrrrz August 31, 2026 15:19
@Tyrrrz Tyrrrz changed the title Fix generated code containing raw newlines in string literals for multiline Description values Fix generated code compilation errors when any description contains newlines Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiline Description on [Command] / [CommandOption] / [CommandParameter] produces uncompilable generated code

3 participants