diff --git a/tooling/nargo_fmt/src/visitor/expr.rs b/tooling/nargo_fmt/src/visitor/expr.rs index 433235e0017..b5ff3e523bc 100644 --- a/tooling/nargo_fmt/src/visitor/expr.rs +++ b/tooling/nargo_fmt/src/visitor/expr.rs @@ -39,6 +39,25 @@ impl FmtVisitor<'_> { self.format_expr(infix.rhs) ) } + ExpressionKind::MethodCall(method_call_expr) => { + let formatted_object = self.format_expr(method_call_expr.object).trim().to_string(); + let formatted_args = method_call_expr + .arguments + .iter() + .map(|arg| { + let arg_str = self.format_expr(arg.clone()).trim().to_string(); + if arg_str.contains('(') { + return arg_str + .replace(" ,", ",") + .replace("( ", "(") + .replace(" )", ")"); + } + arg_str + }) + .collect::>() + .join(", "); + format!("{}.{}({})", formatted_object, method_call_expr.method_name, formatted_args) + } ExpressionKind::MemberAccess(member_access_expr) => { let lhs_str = self.format_expr(member_access_expr.lhs); format!("{}.{}", lhs_str, member_access_expr.rhs) diff --git a/tooling/nargo_fmt/tests/expected/method_call.nr b/tooling/nargo_fmt/tests/expected/method_call.nr new file mode 100644 index 00000000000..c2ee71237f8 --- /dev/null +++ b/tooling/nargo_fmt/tests/expected/method_call.nr @@ -0,0 +1,3 @@ +fn foo() { + my_object.some_method(10, var_value, inner_method(20, 30)); +} diff --git a/tooling/nargo_fmt/tests/input/method_call.nr b/tooling/nargo_fmt/tests/input/method_call.nr new file mode 100644 index 00000000000..175647b4650 --- /dev/null +++ b/tooling/nargo_fmt/tests/input/method_call.nr @@ -0,0 +1,3 @@ +fn foo() { + my_object . some_method( 10,var_value,inner_method( 20 , 30) ); +}