Keep the break which follows an opening parenthesis - #163
Merged
Conversation
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
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
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #163 +/- ##
==========================================
- Coverage 93.90% 93.80% -0.10%
==========================================
Files 9 9
Lines 1576 1583 +7
Branches 363 365 +2
==========================================
+ Hits 1480 1485 +5
- Misses 25 26 +1
- Partials 71 72 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Closes #152.
The issue's remaining item was the line break before the first argument, which the analysis there said was already gone from the syntax tree by the time
UnwrapExtensionran, cause unlocated. It isVisitArgumentList:Roslyn puts the newline that follows a token in that token's trailing trivia, so stripping the opening parenthesis's trailing trivia is stripping the break after
(. That is right when the list empties -(and)should meet - but the condition is only that the last argument went, which is every call ending in aCancellationToken. So the break went, and the first argument kept the indentation which had placed it at the start of a line:Now it is stripped only when nothing remains to put on that line.
ArgumentTests.KeepLineBreaksWhenTheLastArgumentIsDroppedcovers this with no extension methods involved, which is where the bug actually lives.That in turn unblocks the half of
UnwrapExtensionwhich #152 recorded as not working. With the list still broken where it was written to break, the receiver can take the line the argument it displaces was starting, and the comma between them can take the break:One test changes meaning
CSharp_14_ExtensionUnwrapsOntoOneLineasserted that a two argument call collapsed onto a single line. That was never designed - #150 added the test to cover the receiver's own trivia, and the collapsing came from this bug removing a break the author had written. The generator preserves the layout it is given everywhere else, so preserving it here too is the consistent answer, and the test is renamed toCSharp_14_ExtensionDropsTheChainBreakAfterTheReceiverto say what it was built to cover.If you would rather short lists collapse, that is a formatting decision the generator does not currently make anywhere, and worth its own issue rather than resting on this bug.
337 tests pass on net10.0, 295 on net472, clean build.