Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Luau: fix indentation of leading token in union/intersection when hanging #933

Merged
merged 3 commits into from
Nov 30, 2024
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/[email protected]
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