Repository navigation
Conversation
…all formatting idempotent
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 #1193
Problem
function_args_multiline_heuristicdecides whether a table argument is "multiline" by checking whether the input already has a newline after{. That makes the result depend on how the input was laid out.First pass. The last table is written on one line and is far too wide, so it's counted at its full width. The call goes over budget and every argument goes on its own line. On its own line the table still doesn't fit, so it gets expanded:
Second pass. The table now starts with a newline after
{, so it counts as an expanded argument and gets hugged:So
stylua file.lua && stylua --check file.luafails.Fix
In the table-constructor branch of the heuristic, a table written on one line is now also treated as expanded when it can't fit on a line of its own, at the indentation the expanded arguments would use (plus its trailing comma). Such a table is expanded by the formatter either way, so this decides the layout the same way the second pass does. For those tables, only the opening
{is counted towards the current line, as for a table that is already expanded.Tables that do fit on their own line are unaffected, as are tables that are already expanded.
Tests
tests/inputs/function-call-hug-table-idempotent.lua(the repro from the issue), with its snapshot.test_standard_is_idempotent, which formats that input twice and asserts the results are equal. It fails onmainand passes with this change.cargo test --all-features --tests).lsp::testsfailures I see on Windows also fail onmain(path handling) and are unrelated.cargo fmt --checkandcargo clippyare clean. Changelog updated.Real-world code that relied on the old first-pass output may now hug in the first pass, which matches what a second pass already produced. The external comparison run will show those diffs.