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 @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fixed regression where configuration present in current working directory not used when formatting from stdin and no `--stdin-filepath` is provided ([#928](https://github.com/JohnnyMorganz/StyLua/issues/928))
- Luau: fixed incorrect indentation for leading token in union / intersection when hanging ([#932](https://github.com/JohnnyMorganz/StyLua/issues/932))

## [2.0.1] - 2024-11-18

Expand Down
19 changes: 15 additions & 4 deletions src/formatters/luau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,15 @@ fn hang_type_info(
is_first = false;
}

// TODO: handle leading
TypeInfo::Union(TypeUnion::new(union.leading().cloned(), types))
// TODO: leading should play a role in the shape computation
// TODO(#910): we should decide whether we add or remove a leading token (maybe if hang_level = 0?)

TypeInfo::Union(TypeUnion::new(
union
.leading()
.map(|token| fmt_symbol!(ctx, token, "| ", shape)),
types,
))
}

TypeInfo::Intersection(intersection) => {
Expand Down Expand Up @@ -884,9 +891,13 @@ fn hang_type_info(
is_first = false;
}

// TODO: handle leading
// TODO: leading should play a role in the shape computation
// TODO(#910): we should decide whether we add or remove a leading token (maybe if hang_level = 0?)

TypeInfo::Intersection(TypeIntersection::new(
intersection.leading().cloned(),
intersection
.leading()
.map(|token| fmt_symbol!(ctx, token, "& ", shape)),
types,
))
}
Expand Down
9 changes: 9 additions & 0 deletions tests/inputs-luau/type-hanging-leading-token-1.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type Foo =
| numberaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
| numberaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
| numberaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

export type Foo =
& numberaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
& numberaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
& numberaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
15 changes: 15 additions & 0 deletions tests/snapshots/tests__luau@type-hanging-leading-token-1.lua.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
source: tests/tests.rs
expression: "format(&contents, LuaVersion::Luau)"
input_file: tests/inputs-luau/type-hanging-leading-token-1.lua
---
export type Foo =
| numberaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
| numberaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
| numberaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

export type Foo =
& numberaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
& numberaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
& numberaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa