Skip to content

Commit

Permalink
chore: move the first element to a new line if the tactic is vertical…
Browse files Browse the repository at this point in the history
… for call expression (#3526)

Co-authored-by: kevaundray <[email protected]>
  • Loading branch information
kek kek kek and kevaundray authored Nov 22, 2023
1 parent 2d7ceb1 commit eec92e4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
7 changes: 5 additions & 2 deletions tooling/nargo_fmt/src/visitor/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl FmtVisitor<'_> {
false,
call_expr.arguments,
args_span,
true,
);

format!("{callee}{args}")
Expand All @@ -86,6 +87,7 @@ impl FmtVisitor<'_> {
false,
method_call_expr.arguments,
args_span,
true,
);

format!("{object}.{method}{args}")
Expand All @@ -104,7 +106,7 @@ impl FmtVisitor<'_> {
format!("{collection}{index}")
}
ExpressionKind::Tuple(exprs) => {
format_parens(None, self.fork(), exprs.len() == 1, exprs, span)
format_parens(None, self.fork(), exprs.len() == 1, exprs, span, false)
}
ExpressionKind::Literal(literal) => match literal {
Literal::Integer(_) | Literal::Bool(_) | Literal::Str(_) | Literal::FmtStr(_) => {
Expand Down Expand Up @@ -412,9 +414,10 @@ fn format_parens(
trailing_comma: bool,
exprs: Vec<Expression>,
span: Span,
soft_newline: bool,
) -> String {
let tactic = max_width.map(Tactic::LimitedHorizontalVertical).unwrap_or(Tactic::Horizontal);
format_seq("(", ")", visitor, trailing_comma, exprs, span, tactic, false)
format_seq("(", ")", visitor, trailing_comma, exprs, span, tactic, soft_newline)
}

fn format_exprs(
Expand Down
32 changes: 22 additions & 10 deletions tooling/nargo_fmt/tests/expected/call.nr
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
fn foo() {
my_function(10, some_value, another_func(20, 30));

outer_function(some_function(), // Original inner function call
outer_function(
some_function(), // Original inner function call
another_function() // Original inner function call
);

outer_function(some_function(), // Original inner function call
outer_function(
some_function(), // Original inner function call
another_function() // Original inner function call
);

my_function(// Comment
my_function(
// Comment
some_value,
/* Multiline
Comment */
another_func(20, 30));
another_func(20, 30)
);

my_function(some_function(10, "arg1", another_function()),
another_func(20, some_function(), 30));
my_function(
some_function(10, "arg1", another_function()),
another_func(20, some_function(), 30)
);

outer_function(some_function(),
another_function(some_function(), some_value));
outer_function(
some_function(),
another_function(some_function(), some_value)
);

assert_eq(x, y);

Expand All @@ -31,6 +39,10 @@ fn foo() {

assert(x == y);

assert(p4_affine.eq(Gaffine::new(6890855772600357754907169075114257697580319025794532037257385534741338397365,
4338620300185947561074059802482547481416142213883829469920100239455078257889)));
assert(p4_affine.eq(
Gaffine::new(
6890855772600357754907169075114257697580319025794532037257385534741338397365,
4338620300185947561074059802482547481416142213883829469920100239455078257889
)
));
}
6 changes: 4 additions & 2 deletions tooling/nargo_fmt/tests/expected/contract.nr
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ contract Benchmarking {
fn increment_balance(owner: Field, value: Field) {
let current = storage.balances.at(owner).read();
storage.balances.at(owner).write(current + value);
let _callStackItem1 = context.call_public_function(context.this_address(),
let _callStackItem1 = context.call_public_function(
context.this_address(),
compute_selector("broadcast(Field)"),
[owner]);
[owner]
);
}

// Est ultricies integer quis auctor elit sed. In nibh mauris cursus mattis molestie a iaculis.
Expand Down
6 changes: 4 additions & 2 deletions tooling/nargo_fmt/tests/expected/let.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//@error_on_lost_comment=false
fn let_() {
let fn_call = my_function(some_function(10, "arg1", another_function()),
another_func(20, some_function(), 30));
let fn_call = my_function(
some_function(10, "arg1", another_function()),
another_func(20, some_function(), 30)
);
let array = [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]], [[13, 14, 15], [16, 17, 18]]];

let padded_sha256_hash: [u8; 259] = [
Expand Down

0 comments on commit eec92e4

Please sign in to comment.