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
9 changes: 9 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,15 @@ 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::Index(index_expr) => {
let formatted_collection =
self.format_expr(index_expr.collection).trim_end().to_string();
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