Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed goto not being recognised for LuaJIT ([#986](https://github.com/JohnnyMorganz/StyLua/issues/986))
- Fixed semicolon removed after a statement ending with an if-expression leading to ambiguous syntax when the next line begins with parentheses ([#1010](https://github.com/JohnnyMorganz/StyLua/issues/1010))
- Luau: Fixed malformed formatting when there is a comment after a type specifier in a local assignment ([#995](https://github.com/JohnnyMorganz/StyLua/issues/995))
- Luau: Fixed long type union formatted onto a single line if there is a comment in between the equals sign and the type union in a type declaration ([#1007](https://github.com/JohnnyMorganz/StyLua/issues/1007))

## [2.1.0] - 2025-04-21

Expand Down
7 changes: 6 additions & 1 deletion src/formatters/luau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,12 @@ fn attempt_assigned_type_tactics(
let declaration = if contains_comments(strip_trivia(type_info)) {
hang_type_info(ctx, type_info, TypeInfoContext::new(), shape, 0)
} else {
format_type_info(ctx, type_info, shape)
let proper_declaration = format_type_info(ctx, type_info, shape);
if shape.test_over_budget(&proper_declaration) {
hang_type_info(ctx, type_info, TypeInfoContext::new(), shape, 0)
} else {
proper_declaration
}
};

// Take the leading comments and format them nicely
Expand Down
41 changes: 41 additions & 0 deletions tests/inputs-luau/type-hanging-4.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export type ThemeKey = -- NOTE: Luau will introduce keyof in the new type solver! replace this when available
| "fontFace"
| "monoFontFace"
| "accent"
| "background"
| "foreground"
| "windowBackground"
| "windowBorder"
| "windowTitleBackground"
| "windowTitleForeground"
| "windowShadow"
| "windowButtonMinimize"
| "windowButtonMaximize"
| "windowButtonClose"
| "appBackground"
| "appForeground"
| "buttonBackground"
| "buttonForeground"
| "buttonHoverBackground"
| "buttonHoverForeground"
| "buttonPressedBackground"
| "buttonPressedForeground"
| "buttonDisabledBackground"
| "buttonDisabledForeground"
| "inputBackground"
| "inputForeground"
| "inputPlaceholder"
| "inputBorder"
| "selectionBackground"
| "selectionForeground"
| "scrollbarBackground"
| "scrollbarThumb"
| "menuBackground"
| "menuForeground"
| "menuHighlight"
| "notificationBackground"
| "notificationForeground"
| "error"
| "warning"
| "success"
| "info"
46 changes: 46 additions & 0 deletions tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
source: tests/tests.rs
expression: "format(&contents, LuaVersion::Luau)"
input_file: tests/inputs-luau/type-hanging-4.lua
---
export type ThemeKey = -- NOTE: Luau will introduce keyof in the new type solver! replace this when available
| "fontFace"
| "monoFontFace"
| "accent"
| "background"
| "foreground"
| "windowBackground"
| "windowBorder"
| "windowTitleBackground"
| "windowTitleForeground"
| "windowShadow"
| "windowButtonMinimize"
| "windowButtonMaximize"
| "windowButtonClose"
| "appBackground"
| "appForeground"
| "buttonBackground"
| "buttonForeground"
| "buttonHoverBackground"
| "buttonHoverForeground"
| "buttonPressedBackground"
| "buttonPressedForeground"
| "buttonDisabledBackground"
| "buttonDisabledForeground"
| "inputBackground"
| "inputForeground"
| "inputPlaceholder"
| "inputBorder"
| "selectionBackground"
| "selectionForeground"
| "scrollbarBackground"
| "scrollbarThumb"
| "menuBackground"
| "menuForeground"
| "menuHighlight"
| "notificationBackground"
| "notificationForeground"
| "error"
| "warning"
| "success"
| "info"
Loading