You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
collapse_simple_statement = "Input" unnecessarily expands hugged calls with multiline function arguments (2.6.0 regression) #1175
Since 2.6.0 (the Input mode for collapse_simple_statement, #1112), function calls whose arguments contain a multiline anonymous function followed by other arguments get expanded onto multiple lines — even though the input already had them hugged, and the default Never mode keeps them untouched.
The expansion triggers once len(return-line) + ~25 > column_width, so any sufficiently long body inside the function argument sets it off — even though the body is formatted independently and its length is irrelevant to how the call itself should be laid out. With Never the call stays hugged no matter how long the body lines are.
Analysis
In function_args_multiline_heuristic (src/formatters/functions.rs), each function argument is classified via:
let is_expanded = !should_collapse_function_body(ctx, anonymous_function.body());
The problem: anonymous_function here is the argument already re-formatted by the heuristic's first pass (infinite width). should_collapse_function_body in Input mode decides based on node_spans_single_line, which reads token positions — but the re-formatted AST's tokens carry synthetic positions (everything on "line 0"), so a function that was multiline in the input is always classified as collapsed (is_expanded = false).
The heuristic then takes the collapsed branch, which adds the entire single-line rendering of the argument (argument.to_string().len(), 121 chars here) to the running width — going over budget and expanding the call.
Suggested fix
Determine is_expanded from the actual shape of the re-formatted argument — e.g. whether there is a newline in the trivia after the parameters parentheses or before the end token — the same approach the adjacent TableConstructor branch already uses.
Activity