Skip to content

Commit

Permalink
Fix vertical alignment of array brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
mjambon committed Jun 7, 2022
1 parent 3ee6a07 commit b177c83
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
18 changes: 17 additions & 1 deletion lib/pretty.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ let is_atom (x: [> t]) =
let is_atom_list l =
List.for_all is_atom l

(*
inside_box: indicates that we're already within a box that imposes
a certain style and we shouldn't create a new one. This is used for
printing field values like this:
foo: [
bar
]
rather than something else like
foo:
[
bar
]
*)
let rec format ~inside_box std (out:Format.formatter) (x:t) : unit =
match x with
| `Null -> Format.pp_print_string out "null"
Expand Down Expand Up @@ -83,7 +99,7 @@ let rec format ~inside_box std (out:Format.formatter) (x:t) : unit =
#endif
| `List [] -> Format.pp_print_string out "[]"
| `List l ->
if not inside_box then Format.fprintf out "@[<hov2>";
if not inside_box then Format.fprintf out "@[<hv2>";
if is_atom_list l then
(* use line wrapping like we would do for a paragraph of text *)
Format.fprintf out "[@;<1 0>@[<hov>%a@]@;<1 -2>]"
Expand Down
3 changes: 2 additions & 1 deletion test/pretty/atd.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
[ "V3", "testing" ],
[ "V44", 255 ],
[ "V5", "None" ],
[ "V5", [ "Some", true ] ] ],
[ "V5", [ "Some", true ] ]
],
{ "v2": "A" },
{ "v2": [ "B", 100 ] },
[ "C1", [ "C2", true ], [ "C2", false ] ],
Expand Down

0 comments on commit b177c83

Please sign in to comment.