Skip to content

Split concat chains led by a multi-line long string when over width - #1184

Open
Anatomydotexe wants to merge 4 commits into
JohnnyMorganz:mainfrom
Anatomydotexe:fix/concat-multiline-string-hang
Open

Anatomydotexe wants to merge 4 commits into
JohnnyMorganz:mainfrom
Anatomydotexe:fix/concat-multiline-string-hang

Conversation

@Anatomydotexe

Copy link
Copy Markdown

Fixes #1174.

Problem

An assignment whose RHS is a .. concatenation chain that starts with a multi-line long string ([[ ... ]]) was never split, even when the remaining part of the chain went far past column_width. When deciding whether to hang the chain, only the first line of the RHS was measured, so the long tail after ]] was never taken into account.

Change

src/formatters/assignment.rs: for a concat chain led by a multi-line long string, the hang decision now looks at the formatted expression and only hangs it when hanging actually brings it within budget. Other RHS shapes keep their current behaviour.

Tests

  • New snapshot input tests/inputs/concat-multiline-string-chain.lua (+ snapshot): a [[ ]]-led chain over width now splits after ]]; plain-string chains and short chains are unchanged.
  • New tests/test_concat_idempotence.rs: formatting the output a second time yields no changes, including a parenthesised ([[ ... ]]) lead (an earlier iteration of this patch was not idempotent there).
  • Run locally on Linux: cargo test for the default, no-default, all-features, luau, lua52, lua53, lua54, luajit and cfxlua feature sets, plus cargo fmt --check and cargo clippy; all pass. The new tests fail without the change.
  • Also ran the formatter over the repos used by run_comparisons.py (4257 files): no output differences against main, and no new non-idempotent files.

Limits

  • Not run: Windows and wasm32 builds (only CI covers those).
  • At very narrow widths the fix is conservative: if hanging would not fit either, the previous output is kept.

This change was prepared with AI coding agents and reviewed by me before submission.

This branch has not been deployed

No deployments
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.

StyLua failing to follow line limit

1 participant