Skip to content

Keep the break which follows an opening parenthesis - #163

Merged
virzak merged 2 commits into
masterfrom
fix/152-first-argument-line-break
Aug 27, 2026
Merged

Keep the break which follows an opening parenthesis#163
virzak merged 2 commits into
masterfrom
fix/152-first-argument-line-break

Conversation

@virzak

@virzak virzak commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

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 UnwrapExtension ran, cause unlocated. It is VisitArgumentList:

if (invalid.Contains(node.Arguments.Count - 1))
{
    retval = retval
        .WithCloseParenToken(@base.CloseParenToken.WithLeadingTrivia())
        .WithOpenParenToken(@base.OpenParenToken.WithTrailingTrivia());
}

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 a CancellationToken. So the break went, and the first argument kept the indentation which had placed it at the start of a line:

ProgressMethod(            1,
    2);

Now it is stripped only when nothing remains to put on that line. ArgumentTests.KeepLineBreaksWhenTheLastArgumentIsDropped covers this with no extension methods involved, which is where the bug actually lives.

That in turn unblocks the half of UnwrapExtension which #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:

-WriteTo(stream, destination,
+WriteTo(
+        stream,
+        destination,
         4096,
         progress: progress);

One test changes meaning

CSharp_14_ExtensionUnwrapsOntoOneLine asserted 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 to CSharp_14_ExtensionDropsTheChainBreakAfterTheReceiver to 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.

virzak added 2 commits August 27, 2026 07:19
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

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.80%. Comparing base (002c0ed) to head (f0ffc4f).

Files with missing lines Patch % Lines
...rc/Zomp.SyncMethodGenerator/AsyncToSyncRewriter.cs 83.33% 1 Missing and 1 partial ⚠️
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.
📢 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.

@virzak
virzak merged commit d6a5eb9 into master Aug 27, 2026
10 checks passed
@virzak
virzak deleted the fix/152-first-argument-line-break branch August 27, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rewritten argument lists keep stranded indentation

1 participant