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

fix: (formatter) indent after infix lhs #6331

Merged
merged 1 commit into from
Oct 24, 2024
Merged
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
27 changes: 23 additions & 4 deletions tooling/nargo_fmt/src/formatter/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,12 @@
}
};

// Indent right after the lhs so that if there's a trailing comment,
// the next line is indented correctly.
if increase_indentation {
group.increase_indentation();
}

let mut comment_chunk_after_lhs = self.skip_comments_and_whitespace_chunk();

// If the comment is not empty but doesn't have newlines, it's surely `/* comment */`.
Expand All @@ -719,10 +725,6 @@
group.trailing_comment(comment_chunk_after_lhs);
}

if increase_indentation {
group.increase_indentation();
}

group.space_or_line();
group.text(self.chunk(|formatter| {
let tokens_count =
Expand Down Expand Up @@ -1421,6 +1423,23 @@
assert_format_with_max_width(src, expected, "one + two + three + four".len() - 1);
}

#[test]
fn format_infix_with_trailing_comments() {
let src = "fn foo() {
let x = 1 // one
+ 2 // two
+ 3; // three
}
";
let expected = "fn foo() {
let x = 1 // one
+ 2 // two
+ 3; // three
}
";
assert_format(src, expected);
}

#[test]
fn format_empty_block() {
let src = "global x = { } ;";
Expand Down Expand Up @@ -1652,9 +1671,9 @@

#[test]
fn format_method_call_chain_3() {
let src = "fn foo() { assert(p4_affine.eq(Gaffine::new(6890855772600357754907169075114257697580319025794532037257385534741338397365, 4338620300185947561074059802482547481416142213883829469920100239455078257889))); }";

Check warning on line 1674 in tooling/nargo_fmt/src/formatter/expression.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (Gaffine)
let expected = "fn foo() {
assert(p4_affine.eq(Gaffine::new(

Check warning on line 1676 in tooling/nargo_fmt/src/formatter/expression.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (Gaffine)
6890855772600357754907169075114257697580319025794532037257385534741338397365,
4338620300185947561074059802482547481416142213883829469920100239455078257889,
)));
Expand Down Expand Up @@ -1690,7 +1709,7 @@
fn format_nested_method_call_with_maximum_width_2() {
let src = "fn foo() {
assert(
p4_affine.eq(Gaffine::new(

Check warning on line 1712 in tooling/nargo_fmt/src/formatter/expression.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (Gaffine)
6890855772600357754907169075114257697580319025794532037257385534741338397365,
4338620300185947561074059802482547481416142213883829469920100239455078257889,
)),
Expand All @@ -1698,7 +1717,7 @@
}
";
let expected = "fn foo() {
assert(p4_affine.eq(Gaffine::new(

Check warning on line 1720 in tooling/nargo_fmt/src/formatter/expression.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (Gaffine)
6890855772600357754907169075114257697580319025794532037257385534741338397365,
4338620300185947561074059802482547481416142213883829469920100239455078257889,
)));
Expand Down
Loading