Keep the enclosing indent on multi-line expression bodies - #114
Merged
Merged
Conversation
PropertyTemplate.ExpressionBodyFactory and AccessorKind.Expression wrote the rendered expression as one string, and IndentedTextWriter only indents at the start of a write, so every line after the first lost the enclosing indent. A factory ending in WriteLine also left the semicolon alone on its own line. Both paths now go through TemplateRendering.WriteExpressionBody. It keeps the first line after the arrow, splices the rest at the current indent, and puts the semicolon on the last line that has content. Fixes #112 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019StKk4VdpfAZ5cdW5X685e
Groups the two body writers together, and keeps this change from touching the same lines as the string-literal escaping in #113. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019StKk4VdpfAZ5cdW5X685e
…expression-bodies
SonarCloud's coverage gate (80% on new code) flagged these two branches as untested. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019StKk4VdpfAZ5cdW5X685e
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #112
What was wrong
PropertyTemplate.ExpressionBodyFactoryandAccessorKind.Expressionrendered the expression fragment and passed it toWriteas one string.IndentedTextWriteronly indents at the start of a write, so every line after the first landed at the fragment's own indent instead of the enclosing one. Switch expressions, collection expressions and initializers all came out mis-indented. A factory that ended withWriteLinealso left the;alone on its own line.Change
TemplateRendering.WriteExpressionBody, which both expression paths now call:=>and keeps the first line on the declaration line.SpliceFragmentdoes for block bodies.;on the last line that has content.Tests
AMultiLineExpressionBodiedPropertyKeepsTheEnclosingIndent: the switch-expression reproduction from the issue, nested in a class.AMultiLineExpressionBodiedAccessorKeepsTheEnclosingIndent: a collection-expression getter nested in a class.AnExpressionBodyEndingInALineTerminatorKeepsItsSemicolonOnTheLastLine: a factory that ends withWriteLine.S8969inDocComment.cs.This stands alone on
main. It touchesTemplateRendering.cs, as #113 does, but in separate methods.🤖 Generated with Claude Code
https://claude.ai/code/session_019StKk4VdpfAZ5cdW5X685e
Generated by Claude Code