Repository navigation
Conversation
With `collapse_simple_statement = "Input"`, the function call argument heuristic checked whether an anonymous function argument was expanded using the reformatted argument. The reformatted node no longer has the input positions that `Input` mode relies on, so a multiline function was treated as collapsed, its single-line width counted against the column width, and the whole call was expanded. Use the original argument's function body for that check instead. Fixes JohnnyMorganz#1175
This branch has not been deployed
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.
Fixes #1175
With
collapse_simple_statement = "Input", a call whose anonymous function argument is written across multiple lines, e.g.was expanded to
pcall(\n\tfunction()\n\t\t...\n\tend,\n\t5\n)once the single-line width of the whole call (the call prefix, the collapsed function and the remaining arguments) exceededcolumn_width. The root cause comes from #1112:function_args_multiline_heuristicdecides whether a function argument is expanded by callingshould_collapse_function_bodyon the argument after it has been reformatted, and the reformatted node no longer has the input positions thatInputmode uses to tell whether the function was single-line, so a multiline function was treated as collapsed.This change passes the original argument's function body to that check instead (the reformatted one is still used for the width calculation). I went with this rather than checking the reformatted function for newline trivia, as done for tables in the branch below, because it keeps the exact predicate that
format_function_bodyuses for the same node, soAlways,NeverandFunctionOnlyare unaffected by construction and no function signatures need to change.Tests added in
tests/tests.rs, sharing one input:Inputmode: the input from the issue stays hugged; the same function written on a single line stays single-line and the call is still expanded when too wide; a multiline function as the last argument stays hugged; a short single-line function argument stays single-line.Alwaysmode: the same input, which formats identically before and after this change.The
Inputtest fails without the fix and passes with it. I also rancargo testfor the 9 feature combinations fromci.yml,cargo clippy --all-features -- -D warningsandcargo fmt -- --checkbefore and after the change (rustc 1.99.1, Linux x86_64); the only difference in test results is the two new tests. Formatting the issue input and a few call variants (method calls,local ok = pcall(...), nested calls, functions in tables) gives identical output before and after inAlways,NeverandFunctionOnlymodes, andInputoutput passes--verifyand is stable when formatted again. I did not run the wasm, Docker or large-scale comparison workflows.