From 54a8b3b0d082dbee8477b77e68150e1e156119a7 Mon Sep 17 00:00:00 2001 From: Jonathan Bursztyn Date: Thu, 12 Oct 2023 10:18:38 +0100 Subject: [PATCH] chore: add call formatter (#3102) Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> --- tooling/nargo_fmt/src/visitor/expr.rs | 10 ++++++++++ tooling/nargo_fmt/tests/expected/call.nr | 4 ++-- tooling/nargo_fmt/tests/input/call.nr | 6 +++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tooling/nargo_fmt/src/visitor/expr.rs b/tooling/nargo_fmt/src/visitor/expr.rs index b5ff3e523bc..7677a6284ec 100644 --- a/tooling/nargo_fmt/src/visitor/expr.rs +++ b/tooling/nargo_fmt/src/visitor/expr.rs @@ -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::>() + .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 diff --git a/tooling/nargo_fmt/tests/expected/call.nr b/tooling/nargo_fmt/tests/expected/call.nr index ca4d5b82683..105a69acedc 100644 --- a/tooling/nargo_fmt/tests/expected/call.nr +++ b/tooling/nargo_fmt/tests/expected/call.nr @@ -1,3 +1,3 @@ -fn main() { - main(4, 3); +fn foo() { + my_function(10, some_value, another_func(20, 30)); } diff --git a/tooling/nargo_fmt/tests/input/call.nr b/tooling/nargo_fmt/tests/input/call.nr index 8927ebc85db..93d2597a05c 100644 --- a/tooling/nargo_fmt/tests/input/call.nr +++ b/tooling/nargo_fmt/tests/input/call.nr @@ -1,3 +1,3 @@ -fn main() { - main(4, 3); -} \ No newline at end of file +fn foo() { + my_function( 10,some_value,another_func( 20 , 30) ); +}