Skip to content

Commit

Permalink
added closures to protected zone
Browse files Browse the repository at this point in the history
  • Loading branch information
dean-starkware committed Jan 13, 2025
1 parent cf06407 commit 14940a6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
15 changes: 9 additions & 6 deletions crates/cairo-lang-formatter/src/node_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ impl SyntaxNodeFormat for SyntaxNode {
| SyntaxKind::ExprUnary => Some(3),
_ => None,
},

Some(SyntaxKind::ExprClosure) => match self.kind(db) {
SyntaxKind::ClosureParamWrapperNAry => Some(3),
SyntaxKind::ReturnTypeClause => Some(2),
SyntaxKind::ExprBlock => Some(1),
_ => None,
},

Some(SyntaxKind::ExprIf) => match self.kind(db) {
SyntaxKind::ExprBlock => Some(1),
SyntaxKind::ConditionExpr | SyntaxKind::ConditionLet => Some(2),
Expand Down Expand Up @@ -527,12 +535,7 @@ impl SyntaxNodeFormat for SyntaxNode {
trailing: trailing_break_point,
}
}
SyntaxKind::ParamList
if !matches!(
parent_kind(db, self),
Some(SyntaxKind::ClosureParamWrapperNAry)
) =>
{
SyntaxKind::ParamList => {
let leading_break_point = BreakLinePointProperties::new(
2,
BreakLinePointIndentation::IndentedWithTail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,8 @@ fn comment_remains_after_last_comma() {
fn struct_line_breaking() {
let MyStruct {long_long_long_long_key_a, long_long_long_long_key_b, long_long_long_long_key_c, long_long_long_long_key_d, long_long_long_long_key_e, } = my_val;
}
fn closure_line_breaking() {
let closure__with_a_vey_very_very_very_very_very_very_very_larg_name = |left: usize, right: usize| -> usize {

Check warning on line 86 in crates/cairo-lang-formatter/test_data/cairo_files/linebreaking.cairo

View workflow job for this annotation

GitHub Actions / typos

"vey" should be "very".

Check warning on line 86 in crates/cairo-lang-formatter/test_data/cairo_files/linebreaking.cairo

View workflow job for this annotation

GitHub Actions / typos

"larg" should be "large".
left + right
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,15 @@ fn bar(
21 | 2 | 21 | 2 | 21 | 2 | 21 | 2 | 21 | 2 | 21 | 2 | 21 | 2 | 21 | 2 | 21 | 2 | 21 | 2 |
21 | 2 | 21 | 2 | 21 | 2 | 21 | 2 | 21 | 2 | 21 | 2 | 21 | 2 | 21 | 2 | 2 | 3 => 4,
}
let foo = |first_arg: T,
second_arg: T,
third_arg: T,
fourth_arg: T,
fifth_arg: T,
sixth_arg: T,
seventh_arg: T| {
let foo = |
first_arg: T,
second_arg: T,
third_arg: T,
fourth_arg: T,
fifth_arg: T,
sixth_arg: T,
seventh_arg: T,
| {
1
+ 2
+ 3
Expand Down Expand Up @@ -304,3 +306,10 @@ fn struct_line_breaking() {
long_long_long_long_key_e,
} = my_val;
}
fn closure_line_breaking() {
let closure__with_a_vey_very_very_very_very_very_very_very_larg_name = |

Check warning on line 310 in crates/cairo-lang-formatter/test_data/expected_results/linebreaking.cairo

View workflow job for this annotation

GitHub Actions / typos

"vey" should be "very".

Check warning on line 310 in crates/cairo-lang-formatter/test_data/expected_results/linebreaking.cairo

View workflow job for this annotation

GitHub Actions / typos

"larg" should be "large".
left: usize, right: usize,
| -> usize {
left + right
};
}

0 comments on commit 14940a6

Please sign in to comment.