From 726a26c284e4102629344489447c5e478040594b Mon Sep 17 00:00:00 2001 From: Jonathan Bursztyn Date: Wed, 11 Oct 2023 16:02:15 +0100 Subject: [PATCH 1/4] Add Call expression, with test --- tooling/nargo_fmt/src/visitor/expr.rs | 9 +++++++++ tooling/nargo_fmt/tests/expected/call.nr | 4 ++-- tooling/nargo_fmt/tests/input/call.nr | 6 +++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tooling/nargo_fmt/src/visitor/expr.rs b/tooling/nargo_fmt/src/visitor/expr.rs index fa55ac71f78..27bae3f7ce8 100644 --- a/tooling/nargo_fmt/src/visitor/expr.rs +++ b/tooling/nargo_fmt/src/visitor/expr.rs @@ -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 + .iter() + .map(|arg| self.format_expr(arg.clone())) + .collect::>() + .join(", "); + format!("{}({})", formatted_func, formatted_args) + } ExpressionKind::Literal(literal) => match literal { Literal::Integer(_) => slice!(self, span.start(), span.end()).to_string(), Literal::Array(ArrayLiteral::Repeated { repeated_element, length }) => { 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) ); +} From 4260783774beaff43bac8f5a8c9555be869c0454 Mon Sep 17 00:00:00 2001 From: Jonathan Bursztyn Date: Wed, 11 Oct 2023 17:08:06 +0100 Subject: [PATCH 2/4] cargo fmt --- tooling/nargo_fmt/src/visitor/expr.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tooling/nargo_fmt/src/visitor/expr.rs b/tooling/nargo_fmt/src/visitor/expr.rs index 27bae3f7ce8..f81ec8bbfbd 100644 --- a/tooling/nargo_fmt/src/visitor/expr.rs +++ b/tooling/nargo_fmt/src/visitor/expr.rs @@ -41,7 +41,8 @@ impl FmtVisitor<'_> { } ExpressionKind::Call(call_expr) => { let formatted_func = self.format_expr(*call_expr.func); - let formatted_args = call_expr.arguments + let formatted_args = call_expr + .arguments .iter() .map(|arg| self.format_expr(arg.clone())) .collect::>() From f2884f9c4be92f85215dac6a7bcb3f17d9853624 Mon Sep 17 00:00:00 2001 From: Jonathan Bursztyn Date: Wed, 11 Oct 2023 17:57:14 +0100 Subject: [PATCH 3/4] Update tooling/nargo_fmt/src/visitor/expr.rs Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> --- tooling/nargo_fmt/src/visitor/expr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tooling/nargo_fmt/src/visitor/expr.rs b/tooling/nargo_fmt/src/visitor/expr.rs index ec8263ada09..9f89dc7976a 100644 --- a/tooling/nargo_fmt/src/visitor/expr.rs +++ b/tooling/nargo_fmt/src/visitor/expr.rs @@ -43,8 +43,8 @@ impl FmtVisitor<'_> { let formatted_func = self.format_expr(*call_expr.func); let formatted_args = call_expr .arguments - .iter() - .map(|arg| self.format_expr(arg.clone())) + .into_iter() + .map(|arg| self.format_expr(arg)) .collect::>() .join(", "); format!("{}({})", formatted_func, formatted_args) From bd612d7e6a4634ea52759ca0ec77827ae0fb681a Mon Sep 17 00:00:00 2001 From: Jonathan Bursztyn Date: Wed, 11 Oct 2023 18:09:58 +0100 Subject: [PATCH 4/4] Fix format --- tooling/nargo_fmt/src/visitor/expr.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tooling/nargo_fmt/src/visitor/expr.rs b/tooling/nargo_fmt/src/visitor/expr.rs index 9f89dc7976a..b87b24e1983 100644 --- a/tooling/nargo_fmt/src/visitor/expr.rs +++ b/tooling/nargo_fmt/src/visitor/expr.rs @@ -48,6 +48,7 @@ impl FmtVisitor<'_> { .collect::>() .join(", "); format!("{}({})", formatted_func, formatted_args) + } ExpressionKind::Index(index_expr) => { let formatted_collection = self.format_expr(index_expr.collection).trim_end().to_string();