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 @@
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()
jfecher marked this conversation as resolved.
Show resolved Hide resolved
.map(|arg| self.format_expr(arg.clone()))
jonybur marked this conversation as resolved.
Show resolved Hide resolved
.collect::<Vec<_>>()
.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 }) => {
Expand Down Expand Up @@ -96,7 +106,7 @@
if let Some(first_stmt) = block.first() {
let slice = slice!(self, self.last_position, first_stmt.span.start());
let len =
slice.chars().take_while(|ch| ch.is_whitespace()).collect::<String>().rfind('\n');

Check warning on line 109 in tooling/nargo_fmt/src/visitor/expr.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (rfind)
self.last_position += len.unwrap_or(0) as u32;
}
}
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