Repository navigation
Add Input mode for collapse_simple_statement - #1112
JohnnyMorganz merged 9 commits into
Conversation
|
Also closes #863 |
bump to stylua@2.5.2
|
Thanks for working on this — I'm the author of #863, and this addresses what I was hoping for. One gap though: the mode currently only preserves the input shape for functions and if-guards, but regular block statements ( -- input
for i = 0x00, 0x7F do sequence_len_by_byte[i] = 1 end
for i = 0xC0, 0xDF do sequence_len_by_byte[i] = 2 end
for i = 0xE0, 0xEF do sequence_len_by_byte[i] = 3 end
for i = 0xF0, 0xFF do sequence_len_by_byte[i] = 4 endThe same applies to The approach could extend naturally to all block-bearing statements: check whether the whole statement spans a single line in the input and the block is "simple" (a single laststmt / simple stmt, no comments), then inline the block instead of deferring to |
Don't bypass the width check so that over-wide functions still fall back to their multiline form
…reserve-collapse-simple-statement
Adds a new
Inputmode forcollapse_simple_statement.It allows Stylua to preserve whether simple functions and conditionals were originally collapsed or expanded, instead of enforcing one global collapse behavior across the whole codebase.
With this mode:
stays collapsed, while:
stays expanded.
The motivation is making it possible for users to keep a mixed style where some simple statements are collapsed and others are intentionally expanded, not all simple statements carry the same importance in a codebase. In some cases a collapsed statement improves readability by keeping a guard clause or empty function compact, while in others, expanding the statement makes the control flow or intent more visible.
The existing
collapse_simple_statementmodes require users to choose one global behavior: collapse matching statements everywhere, or expand them everywhere. This can be limiting when different simple statements benefit from different formatting choices.And, while
stylua: ignorecomments can work around individual cases, they add noise and become difficult to maintain when used repeatedly for formatting preferences. Adding anInputmode follows the existing input-preserving semantics used by other Stylua rules likecall_parenthesis, and gives users the ability to preserve these choices per situation without changing the default behavior.Note: I used AI assistance while working through parts of the implementation, but reviewed the resulting changes and verified the behavior with tests.
Closes #863