Skip to content

Commit

Permalink
Merge pull request #6241 from ptaszor3/dbg_formatter_issue
Browse files Browse the repository at this point in the history
Fixed format for 'dbg'
  • Loading branch information
bhansconnect authored Dec 11, 2023
2 parents f795d08 + 0019e9f commit 49fb5a6
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 30 deletions.
17 changes: 3 additions & 14 deletions crates/compiler/fmt/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,25 +302,14 @@ fn should_outdent(mut rhs: &TypeAnnotation) -> bool {
}
}

fn fmt_dbg_in_def<'a>(
buf: &mut Buf,
condition: &'a Loc<Expr<'a>>,
is_multiline: bool,
indent: u16,
) {
fn fmt_dbg_in_def<'a>(buf: &mut Buf, condition: &'a Loc<Expr<'a>>, _: bool, indent: u16) {
buf.ensure_ends_with_newline();
buf.indent(indent);
buf.push_str("dbg");

let return_indent = if is_multiline {
buf.newline();
indent + INDENT
} else {
buf.spaces(1);
indent
};
buf.spaces(1);

condition.format(buf, return_indent);
condition.format(buf, indent);
}

fn fmt_expect<'a>(buf: &mut Buf, condition: &'a Loc<Expr<'a>>, is_multiline: bool, indent: u16) {
Expand Down
14 changes: 4 additions & 10 deletions crates/compiler/fmt/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<'a> Formattable for Expr<'a> {
Expect(condition, continuation) => {
condition.is_multiline() || continuation.is_multiline()
}
Dbg(condition, continuation) => condition.is_multiline() || continuation.is_multiline(),
Dbg(condition, _) => condition.is_multiline(),
LowLevelDbg(_, _, _) => unreachable!(
"LowLevelDbg should only exist after desugaring, not during formatting"
),
Expand Down Expand Up @@ -956,22 +956,16 @@ fn fmt_dbg<'a>(
buf: &mut Buf,
condition: &'a Loc<Expr<'a>>,
continuation: &'a Loc<Expr<'a>>,
is_multiline: bool,
_: bool,
indent: u16,
) {
buf.ensure_ends_with_newline();
buf.indent(indent);
buf.push_str("dbg");

let return_indent = if is_multiline {
buf.newline();
indent + INDENT
} else {
buf.spaces(1);
indent
};
buf.spaces(1);

condition.format(buf, return_indent);
condition.format(buf, indent);

// Always put a blank line after the `dbg` line(s)
buf.ensure_ends_with_blank_line();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dbg (
5,
666,
)

4
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Dbg(
@4-16 Tuple(
[
@5-6 Num(
"5",
),
@12-15 SpaceBefore(
Num(
"666",
),
[
Newline,
],
),
],
),
@18-19 SpaceBefore(
Num(
"4",
),
[
Newline,
Newline,
],
),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dbg (5,
666)

4
5 changes: 3 additions & 2 deletions crates/compiler/test_syntax/tests/test_snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ mod test_snapshots {
fail/when_outdented_branch.expr,
fail/when_over_indented_int.expr,
fail/when_over_indented_underscore.expr,
fail/wild_case_arrow.expr,
fail/where_type_variable.expr,
fail/wild_case_arrow.expr,
malformed/bad_opaque_ref.expr,
malformed/malformed_ident_due_to_underscore.expr,
malformed/malformed_pattern_field_access.expr, // See https://github.com/roc-lang/roc/issues/399
Expand Down Expand Up @@ -296,6 +296,7 @@ mod test_snapshots {
pass/control_characters_in_scalar.expr,
pass/crash.expr,
pass/dbg.expr,
pass/dbg_multiline.expr,
pass/def_without_newline.expr,
pass/destructure_tag_assignment.expr,
pass/empty_app_header.header,
Expand Down Expand Up @@ -489,9 +490,9 @@ mod test_snapshots {
pass/where_clause_multiple_has_across_newlines.expr,
pass/where_clause_non_function.expr,
pass/where_clause_on_newline.expr,
pass/where_ident.expr,
pass/zero_float.expr,
pass/zero_int.expr,
pass/where_ident.expr,
// END SNAPSHOTS (for automatic test detection via `env ROC_SNAPSHOT_TEST_OVERWRITE=1 cargo test`)
}

Expand Down

0 comments on commit 49fb5a6

Please sign in to comment.