Skip to content

Indent nested method-call argument lists (#591)#1673

Merged
eric-milles merged 1 commit into
groovy:masterfrom
austek:fix/issue-591-nested-call-indent
May 14, 2026
Merged

Indent nested method-call argument lists (#591)#1673
eric-milles merged 1 commit into
groovy:masterfrom
austek:fix/issue-591-nested-call-indent

Conversation

@austek

@austek austek commented May 12, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #591. Adds extra indentation for nested method-call argument lists whose contents start on a line after the opening paren.

For a multiline statement like

println(m1().
        append("a").
        append("b").
        append(m2(
        "x",
        m1())))

the existing formatter applies a single multiline indent to every continuation line, so "x" and m1() (inside m2(...)) end up at the same column as .append(...) from the outer chain. The new handleNestedParenWraps pass in GroovyIndentation walks the tokens and, for each paren pair that

  • opens with content on the next line (a wrap-open), and
  • is itself contained within another paren

adds another indentationMultiline step to the lines it spans. The outermost wrap is left to the existing multiline-statement rule, so the single-level fixtures (MultilineStatements1/3, MultilineMethodParams*, etc.) are unchanged.

When a method call's argument list spans multiple lines and is itself
nested inside another paren, the inner arguments now receive an
additional indentationMultiline step. Outermost paren-wraps are still
handled by the existing multiline-statement rule, so test fixtures with
a single wrap level (e.g. MultilineStatements1, MultilineStatements3,
MultilineMethodParams*) are unchanged.

see groovy#591
@eric-milles

Copy link
Copy Markdown
Member

I'm not sure how far the pattern of a separate method for each kind of wrapping is going to be doable. But thank you for your contribution.

@eric-milles eric-milles merged commit ea7eae3 into groovy:master May 14, 2026
@austek austek deleted the fix/issue-591-nested-call-indent branch May 15, 2026 18:29
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.

Poor indenting of nested expressions

2 participants