Skip to content

Commit

Permalink
chore: add call formatter (#3102)
Browse files Browse the repository at this point in the history
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
  • Loading branch information
jonybur and TomAFrench committed Oct 12, 2023
1 parent 6f1f90c commit 54a8b3b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 10 additions & 0 deletions tooling/nargo_fmt/src/visitor/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ impl FmtVisitor<'_> {
self.format_expr(infix.rhs)
)
}
ExpressionKind::Call(call_expr) => {
let formatted_func = self.format_expr(*call_expr.func);
let formatted_args = call_expr
.arguments
.into_iter()
.map(|arg| self.format_expr(arg))
.collect::<Vec<_>>()
.join(", ");
format!("{}({})", formatted_func, formatted_args)
}
ExpressionKind::MethodCall(method_call_expr) => {
let formatted_object = self.format_expr(method_call_expr.object).trim().to_string();
let formatted_args = method_call_expr
Expand Down
4 changes: 2 additions & 2 deletions tooling/nargo_fmt/tests/expected/call.nr
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
main(4, 3);
fn foo() {
my_function(10, some_value, another_func(20, 30));
}
6 changes: 3 additions & 3 deletions tooling/nargo_fmt/tests/input/call.nr
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
main(4, 3);
}
fn foo() {
my_function( 10,some_value,another_func( 20 , 30) );
}

0 comments on commit 54a8b3b

Please sign in to comment.