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

chore: add call formatter #3102

Merged
merged 10 commits into from
Oct 12, 2023
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) );
}
Loading