Skip to content

Commit

Permalink
chore: fix bug :)
Browse files Browse the repository at this point in the history
  • Loading branch information
f01dab1e committed Nov 27, 2023
1 parent 01f0bab commit a27789d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
17 changes: 13 additions & 4 deletions tooling/nargo_fmt/src/rewrite/expr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use noirc_frontend::{token::Token, ArrayLiteral, Expression, ExpressionKind, Literal, UnaryOp};

use crate::visitor::{
expr::{format_brackets, format_parens},
expr::{format_brackets, format_parens, NewlineMode},
ExpressionType, FmtVisitor, Indent, Shape,
};

Expand Down Expand Up @@ -60,6 +60,7 @@ pub(crate) fn rewrite(
call_expr.arguments,
args_span,
true,
NewlineMode::IfContainsNewLineAndWidth,
);

format!("{callee}{args}")
Expand All @@ -80,6 +81,7 @@ pub(crate) fn rewrite(
method_call_expr.arguments,
args_span,
true,
NewlineMode::IfContainsNewLineAndWidth,
);

format!("{object}.{method}{args}")
Expand All @@ -97,9 +99,16 @@ pub(crate) fn rewrite(

format!("{collection}{index}")
}
ExpressionKind::Tuple(exprs) => {
format_parens(None, visitor.fork(), shape, exprs.len() == 1, exprs, span, false)
}
ExpressionKind::Tuple(exprs) => format_parens(
None,
visitor.fork(),
shape,
exprs.len() == 1,
exprs,
span,
true,
NewlineMode::Normal,
),
ExpressionKind::Literal(literal) => match literal {
Literal::Integer(_) | Literal::Bool(_) | Literal::Str(_) | Literal::FmtStr(_) => {
visitor.slice(span).to_string()
Expand Down
17 changes: 5 additions & 12 deletions tooling/nargo_fmt/src/visitor/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ impl FmtVisitor<'_> {
}
}

// TODO: fixme
#[allow(clippy::too_many_arguments)]
pub(crate) fn format_seq<T: Item>(
shape: Shape,
Expand Down Expand Up @@ -232,6 +233,8 @@ pub(crate) fn format_brackets(
)
}

// TODO: fixme
#[allow(clippy::too_many_arguments)]
pub(crate) fn format_parens(
max_width: Option<usize>,
visitor: FmtVisitor,
Expand All @@ -240,20 +243,10 @@ pub(crate) fn format_parens(
exprs: Vec<Expression>,
span: Span,
reduce: bool,
mode: NewlineMode,
) -> String {
let tactic = max_width.map(Tactic::LimitedHorizontalVertical).unwrap_or(Tactic::Horizontal);
format_seq(
shape,
"(",
")",
visitor,
trailing_comma,
exprs,
span,
tactic,
NewlineMode::IfContainsNewLineAndWidth,
reduce,
)
format_seq(shape, "(", ")", visitor, trailing_comma, exprs, span, tactic, mode, reduce)
}

fn format_exprs(
Expand Down

0 comments on commit a27789d

Please sign in to comment.