Skip to content

Commit

Permalink
Merge branch 'MAIN' into js-ocp-indent
Browse files Browse the repository at this point in the history
  • Loading branch information
Julow committed Jan 16, 2024
2 parents 27bff54 + aa2ec82 commit 1014e82
Show file tree
Hide file tree
Showing 42 changed files with 398 additions and 105 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ profile. This started with version 0.26.0.
- \* Force a break around comments following an infix operator (fix non-stabilizing comments) (#2478, @gpetiot)
- \* Fix the indentation of tuples in attributes and extensions (#2488, @Julow)
- Fix unstable comment around docked functor argument (#2506, @Julow)
- \* Fix unwanted alignment after comment (#2507, @Julow)
- \* Fix unwanted alignment in if-then-else (#2511, @Julow)

## 0.26.1 (2023-09-15)

Expand Down
4 changes: 2 additions & 2 deletions lib/Cmts.ml
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ let fmt_cmts_aux t (conf : Conf.t) cmts ~fmt_code pos =
| _ -> noop ) )

(** Format comments for loc. *)
let fmt_cmts t conf ~fmt_code ?pro ?epi ?(eol = Fmt.fmt "@\n") ?(adj = eol)
found loc pos =
let fmt_cmts t conf ~fmt_code ?pro ?epi ?(eol = Fmt.fmt "@;<1000 0>")
?(adj = eol) found loc pos =
let open Fmt in
match found with
| None | Some [] -> noop
Expand Down
11 changes: 6 additions & 5 deletions lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3881,10 +3881,11 @@ and fmt_module c ctx ?rec_ ?epi ?(can_sparse = false) keyword ?(eqty = "=")
~fit:true attrs
in
let intro =
str keyword
$ fmt_extension_suffix c ext
$ fmt_attributes c ~pre:(Break (1, 0)) attrs_before
$ fmt_if rec_flag " rec" $ str " " $ fmt_str_loc_opt c name
hvbox 2
( str keyword
$ fmt_extension_suffix c ext
$ fmt_attributes c ~pre:(Break (1, 0)) attrs_before
$ fmt_if rec_flag " rec" $ fmt "@ " $ fmt_str_loc_opt c name )
in
let compact =
Poly.(c.conf.fmt_opts.let_module.v = `Compact) || not can_sparse
Expand Down Expand Up @@ -4201,7 +4202,7 @@ and fmt_module_expr ?(dock_struct = true) c ({ast= m; _} as xmod) =
| Pmod_unpack (e, ty1, ty2) ->
let package_type sep (lid, cstrs) =
break 1 (Params.Indent.mod_unpack_annot c.conf)
$ hvbox 0
$ hovbox 0
( hovbox 0 (str sep $ fmt_longident_loc c lid)
$ fmt_package_type c ctx cstrs )
in
Expand Down
6 changes: 2 additions & 4 deletions lib/Params.ml
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,7 @@ let get_if_then_else (c : Conf.t) ~first ~last ~parens_bch ~parens_prev_bch
( fmt_or_k first
(str "if" $ fmt_opt fmt_extension_suffix)
(str "else if")
$ fmt_attributes
$ fmt_or (Option.is_some fmt_extension_suffix) "@ " " "
$ fmt_cond xcnd )
$ fmt_attributes $ fmt "@ " $ fmt_cond xcnd )
$ fmt "@ " )
; box_keyword_and_expr=
(fun k -> hvbox 2 (fmt_or (Option.is_some xcond) "then" "else" $ k))
Expand All @@ -610,7 +608,7 @@ let get_if_then_else (c : Conf.t) ~first ~last ~parens_bch ~parens_prev_bch
~wrap_breaks:
(get_parens_breaks ~opn_hint_indent:0
~cls_hint:((1, 0), (1000, -2)) )
; box_expr= Some false
; box_expr= None
; expr_pro= None
; expr_eol= None
; branch_expr
Expand Down
8 changes: 6 additions & 2 deletions test/passing/tests/break_separators-after.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,12 @@ let g () =
hhhhhhhhhh |] ->
fooooooooo

let () = match x with _, (* line 1 line 2 *)
Some _ -> x
let () =
match x with
| ( _,
(* line 1 line 2 *)
Some _ ) ->
x

let () =
match x with
Expand Down
8 changes: 6 additions & 2 deletions test/passing/tests/break_separators-after_docked.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,12 @@ let g () =
|] ->
fooooooooo

let () = match x with _, (* line 1 line 2 *)
Some _ -> x
let () =
match x with
| ( _,
(* line 1 line 2 *)
Some _ ) ->
x

let () =
match x with
Expand Down
8 changes: 6 additions & 2 deletions test/passing/tests/break_separators-before_docked.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,12 @@ let g () =
|] ->
fooooooooo

let () = match x with _, (* line 1 line 2 *)
Some _ -> x
let () =
match x with
| ( _
, (* line 1 line 2 *)
Some _ ) ->
x

let () =
match x with
Expand Down
8 changes: 6 additions & 2 deletions test/passing/tests/break_separators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,12 @@ let g () =
; hhhhhhhhhh |] ->
fooooooooo

let () = match x with _, (* line 1 line 2 *)
Some _ -> x
let () =
match x with
| ( _
, (* line 1 line 2 *)
Some _ ) ->
x

let () =
match x with
Expand Down
2 changes: 1 addition & 1 deletion test/passing/tests/comments-no-wrap.ml.err
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Warning: tests/comments.ml:186 exceeds the margin
Warning: tests/comments.ml:190 exceeds the margin
Warning: tests/comments.ml:250 exceeds the margin
Warning: tests/comments.ml:430 exceeds the margin
Warning: tests/comments.ml:434 exceeds the margin
16 changes: 10 additions & 6 deletions test/passing/tests/comments-no-wrap.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,11 @@ let%map
_ =
()

type t = < (* a *)
a: int [@atr] (* b *) ; b: int (* c *) >
type t =
< (* a *)
a: int [@atr] (* b *)
; b: int
(* c *) >

type t = < a: int (* a *) ; (* b *) .. (* c *) >

Expand All @@ -277,8 +280,10 @@ let _ =
| None -> do_something ()
| Some _ -> () (* do nothing *) )

let _ = try_with (fun () -> (* comment before *)
a ; b (* after b *) )
let _ =
try_with (fun () ->
(* comment before *)
a ; b (* after b *) )

let _ =
match x with
Expand All @@ -296,8 +301,7 @@ type t =

type t =
(* | B *)
| A
(* A *)
| A (* A *)
| C

type t =
Expand Down
16 changes: 10 additions & 6 deletions test/passing/tests/comments.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,11 @@ let%map
_ =
()

type t = < (* a *)
a: int [@atr] (* b *) ; b: int (* c *) >
type t =
< (* a *)
a: int [@atr] (* b *)
; b: int
(* c *) >

type t = < a: int (* a *) ; (* b *) .. (* c *) >

Expand All @@ -279,8 +282,10 @@ let _ =
| None -> do_something ()
| Some _ -> () (* do nothing *) )

let _ = try_with (fun () -> (* comment before *)
a ; b (* after b *) )
let _ =
try_with (fun () ->
(* comment before *)
a ; b (* after b *) )

let _ =
match x with
Expand All @@ -298,8 +303,7 @@ type t =

type t =
(* | B *)
| A
(* A *)
| A (* A *)
| C

type t =
Expand Down
3 changes: 2 additions & 1 deletion test/passing/tests/comments_args.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ let emit_wrapper_function =
false (* is_pair_generator *)
hoisted true (* no_injection *)
true (* inout_wrapper *)
is_interceptable false (* is_memoize_impl *)
is_interceptable false
(* is_memoize_impl *)
Rx.NonRx false

[@@@ocamlformat "wrap-fun-args=false"]
Expand Down
4 changes: 2 additions & 2 deletions test/passing/tests/exp_grouping.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ let _ =

let () =
if a
then begin b
(* asd *)
then begin
b (* asd *)
end

[@@@ocamlformat "if-then-else=k-r"]
Expand Down
5 changes: 4 additions & 1 deletion test/passing/tests/extensions-indent.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ let _ = try%lwt Lwt.return 2 with _ -> assert false

let _ =
(* foooooooooooo *)
try%lwt (* fooooooooooo *) Lwt.return 2 with _ -> assert false
try%lwt
(* fooooooooooo *)
Lwt.return 2
with _ -> assert false

let _ =
try%lwt
Expand Down
5 changes: 4 additions & 1 deletion test/passing/tests/extensions.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ let _ = try%lwt Lwt.return 2 with _ -> assert false

let _ =
(* foooooooooooo *)
try%lwt (* fooooooooooo *) Lwt.return 2 with _ -> assert false
try%lwt
(* fooooooooooo *)
Lwt.return 2
with _ -> assert false

let _ =
try%lwt
Expand Down
7 changes: 5 additions & 2 deletions test/passing/tests/extensions_exp_grouping.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,8 @@ let a =
(* test *)
Lwt.return () ;%lwt Lwt.return 1

let a = f ((* test *)
Lwt.return () ;%lwt Lwt.return 1)
let a =
f
( (* test *)
Lwt.return () ;%lwt
Lwt.return 1 )
17 changes: 15 additions & 2 deletions test/passing/tests/ite-compact.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ let foo =
let foo = if cmp < 0 then (* foo *) a + b else (* foo *) a - b

let foo =
if cmp < 0 then (* ast higher precedence than context: no parens *)
if cmp < 0 then
(* ast higher precedence than context: no parens *)
false
else if cmp > 0 then (* context higher prec than ast: add parens *)
else if cmp > 0 then
(* context higher prec than ast: add parens *)
true
else if Poly.(assoc_of_prec prec_ast = which_child && which_child <> Non)
then foo
Expand All @@ -144,3 +146,14 @@ let _ =
foooooooooooooooooooooooooooooooooooooooooo
then foooooooooooooooooooooooooooooooooooooooooo
else foooooooooooooooooooooooooooooooooooooooooo

let _ =
if
(* foo *)
foo
then 0
else if
(* bar *)
bar
then 1
else 2
17 changes: 15 additions & 2 deletions test/passing/tests/ite-compact_closing.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ let foo =
let foo = if cmp < 0 then (* foo *) a + b else (* foo *) a - b

let foo =
if cmp < 0 then (* ast higher precedence than context: no parens *)
if cmp < 0 then
(* ast higher precedence than context: no parens *)
false
else if cmp > 0 then (* context higher prec than ast: add parens *)
else if cmp > 0 then
(* context higher prec than ast: add parens *)
true
else if Poly.(assoc_of_prec prec_ast = which_child && which_child <> Non)
then foo
Expand All @@ -159,3 +161,14 @@ let _ =
foooooooooooooooooooooooooooooooooooooooooo
then foooooooooooooooooooooooooooooooooooooooooo
else foooooooooooooooooooooooooooooooooooooooooo

let _ =
if
(* foo *)
foo
then 0
else if
(* bar *)
bar
then 1
else 2
14 changes: 14 additions & 0 deletions test/passing/tests/ite-fit_or_vertical.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,17 @@ let _ =
foooooooooooooooooooooooooooooooooooooooooo
else
foooooooooooooooooooooooooooooooooooooooooo

let _ =
if
(* foo *)
foo
then
0
else if
(* bar *)
bar
then
1
else
2
14 changes: 14 additions & 0 deletions test/passing/tests/ite-fit_or_vertical_closing.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,17 @@ let _ =
foooooooooooooooooooooooooooooooooooooooooo
else
foooooooooooooooooooooooooooooooooooooooooo

let _ =
if
(* foo *)
foo
then
0
else if
(* bar *)
bar
then
1
else
2
14 changes: 14 additions & 0 deletions test/passing/tests/ite-fit_or_vertical_no_indicate.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,17 @@ let _ =
foooooooooooooooooooooooooooooooooooooooooo
else
foooooooooooooooooooooooooooooooooooooooooo

let _ =
if
(* foo *)
foo
then
0
else if
(* bar *)
bar
then
1
else
2
14 changes: 14 additions & 0 deletions test/passing/tests/ite-kr.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,17 @@ let _ =
foooooooooooooooooooooooooooooooooooooooooo
else
foooooooooooooooooooooooooooooooooooooooooo

let _ =
if
(* foo *)
foo
then
0
else if
(* bar *)
bar
then
1
else
2
Loading

0 comments on commit 1014e82

Please sign in to comment.