Keep the receiver on the same line as the comma after it - #150
Merged
Conversation
Unwrapping an extension call turns the receiver into the first argument, so a call written as a chain across several lines put the line break which had preceded the dot between that argument and its comma: global::Helpers.StreamExtensions.Drain(stream , 1024); Only the leading trivia was being dropped. Drop the trailing trivia as well, since whatever separated the receiver from the dot describes a shape which no longer exists once it is an argument. Generated with Claude Code
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #150 +/- ##
=======================================
Coverage 93.82% 93.82%
=======================================
Files 9 9
Lines 1522 1522
Branches 352 352
=======================================
Hits 1428 1428
Misses 25 25
Partials 69 69 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
virzak
added a commit
that referenced
this pull request
Aug 27, 2026
* Show that dropping the last argument flattens the list
An argument list written across lines, whose last argument is a
CancellationToken, comes out with the first argument stranded after the
opening parenthesis and its original indentation still in front of it:
ProgressMethod( 1,
2);
The snapshot committed here is what it should be instead. The test fails
until the next commit.
Generated with Claude Code
* Keep the break which follows an opening parenthesis
Removing the last argument from a list stripped the trailing trivia of the
opening parenthesis, which is where Roslyn puts the newline that follows
it. Correct when the list empties - `(` and `)` should meet - but it fired
whenever the last argument went, so every call ending in a
CancellationToken lost the break before its first argument and kept the
indentation which had placed that argument at the start of a line.
Only strip it when nothing remains to put on that line. That leaves the
argument list broken where it was written to break, which in turn lets
unwrapping do the thing it could not do before: give the receiver the line
the argument it displaces was starting, and the comma between them the
break, rather than crowding the two onto the parenthesis's line.
-WriteTo(stream, destination,
+WriteTo(
+ stream,
+ destination,
4096,
progress: progress);
This closes the last item in #152.
One test changes meaning rather than merely output.
CSharp_14_ExtensionUnwrapsOntoOneLine asserted that a two argument call
collapsed onto a single line, which was never designed - it was this bug
removing the break the author had written. The generator preserves the
layout it is given everywhere else, so the test is renamed to
CSharp_14_ExtensionDropsTheChainBreakAfterTheReceiver, which is what it
was actually built to cover in #150.
Generated with Claude Code
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.
Problem
Unwrapping an extension call turns the receiver into the first argument. When the call was written as a chain across several lines, the line break which had preceded the dot ended up between that argument and its comma:
Seen in the code generated for SharpCompress, which chains calls that way throughout.
Cause
The receiver was inserted with
expression.WithoutLeadingTrivia(). Its trailing trivia - the break and indent which separated it from the dot - came along, and the comma is emitted after it.Fix
Drop the trailing trivia too. Whatever separated the receiver from the dot describes a shape which no longer exists once the receiver is an argument.
Not addressed here
The generated line still carries the indentation the original arguments had, so it reads as
That comes from the argument trivia rather than from unwrapping, applies equally to calls which were never extensions, and is left for a separate change. The comma placement above was specific to this path.
Verification
First commit is the failing test. Afterwards the full suite passes on both target frameworks with every existing snapshot unchanged, and all three Roslyn variants build.
🤖 Generated with Claude Code