Skip to content

Commit eccc45b

Browse files
fix issue
1 parent 8c87ed2 commit eccc45b

File tree

12 files changed

+45
-22
lines changed

12 files changed

+45
-22
lines changed

lib/Fmt_ast.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ and fmt_function ?force_closing_paren ~ctx ~ctx0 ?pro ~wrap_intro
16641664
( pro_outer
16651665
$ hvbox_if has_cmts_outer 0
16661666
( cmts_outer
1667-
$ Params.Exp.box_fun_decl ~ctx0 c.conf
1667+
$ Params.Exp.box_fun_decl ~ctx0 ~ctx c.conf
16681668
( pro_inner $ cmts_inner
16691669
$ Params.Exp.box_fun_decl_after_pro ~ctx0
16701670
(opn_attr_paren $ opn_paren $ head) ) ) )

lib/Params.ml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,21 @@ module Exp = struct
329329
then Fn.id
330330
else hvbox indent
331331

332-
let box_fun_decl ~ctx0 c k =
333-
match ctx0 with
334-
| Exp {pexp_desc= Pexp_beginend _; _} -> hovbox 2 k
332+
let box_fun_decl ~ctx0 ~ctx c k =
333+
match (ctx0, ctx) with
334+
| Exp {pexp_desc= Pexp_beginend _; _}, _ -> hovbox 2 k
335335
| _ when ocp c -> hvbox 2 k
336336
(* Avoid large indentation for [let _ = function]. *)
337-
| Lb
338-
{ pvb_body= Pfunction_body {pexp_desc= Pexp_function ([], _, _, _); _}
339-
; _ } ->
337+
| ( Lb
338+
{ pvb_body=
339+
Pfunction_body {pexp_desc= Pexp_function ([], _, _, _); _}
340+
; _ }
341+
, _ ) ->
340342
hovbox 2 k
341-
| Str _ | Lb _ | Clf _ | Exp {pexp_desc= Pexp_let _; _} -> hovbox 4 k
343+
| (Str _ | Lb _ | Clf _), _ -> hovbox 4 k
344+
| Exp {pexp_desc= Pexp_let (_, e, _); _}, Exp e'
345+
when not (phys_equal e e') ->
346+
hovbox 4 k
342347
| _ -> hvbox 2 k
343348

344349
let box_fun_decl_after_pro ~ctx0 =

lib/Params.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ module Exp : sig
7878

7979
val single_line_function : ctx:Ast.t -> ctx0:Ast.t -> args:'a list -> bool
8080

81-
val box_fun_decl : ctx0:Ast.t -> Conf.t -> Fmt.t -> Fmt.t
81+
val box_fun_decl : ctx0:Ast.t -> ctx:Ast.t -> Conf.t -> Fmt.t -> Fmt.t
8282
(** Box a function decl from the label to the arrow. *)
8383

8484
val box_fun_decl_after_pro : ctx0:Ast.t -> Fmt.t -> Fmt.t

test/passing/refs.ahrefs/fun_decl.ml.ref

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ let _ =
8383
let _ =
8484
let _ = () in
8585
fun (context : Context.t)
86-
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t) ->
86+
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t)
87+
->
8788
let _ = () in
8889
()
8990

test/passing/refs.ahrefs/js_source.ml.err

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ Warning: js_source.ml:136 exceeds the margin
22
Warning: js_source.ml:170 exceeds the margin
33
Warning: js_source.ml:243 exceeds the margin
44
Warning: js_source.ml:255 exceeds the margin
5-
Warning: js_source.ml:857 exceeds the margin
5+
Warning: js_source.ml:862 exceeds the margin

test/passing/refs.ahrefs/js_source.ml.ref

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,13 @@ let _ =
587587

588588
let _ =
589589
let x = x in
590-
fun foooooooooooooooooo foooooooooooooooooo foooooooooooooooooo
591-
foooooooooooooooooo foooooooooooooooooo foooooooooooooooooo -> ()
590+
fun foooooooooooooooooo
591+
foooooooooooooooooo
592+
foooooooooooooooooo
593+
foooooooooooooooooo
594+
foooooooooooooooooo
595+
foooooooooooooooooo
596+
-> ()
592597

593598
module type For_let_syntax_local =
594599
For_let_syntax_gen

test/passing/refs.default/fun_decl.ml.ref

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ let _ =
8181
let _ =
8282
let _ = () in
8383
fun (context : Context.t)
84-
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t) ->
84+
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t)
85+
->
8586
let _ = () in
8687
()
8788

test/passing/refs.default/js_source.ml.err

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Warning: js_source.ml:224 exceeds the margin
44
Warning: js_source.ml:229 exceeds the margin
55
Warning: js_source.ml:240 exceeds the margin
66
Warning: js_source.ml:328 exceeds the margin
7-
Warning: js_source.ml:809 exceeds the margin
7+
Warning: js_source.ml:814 exceeds the margin

test/passing/refs.default/js_source.ml.ref

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,13 @@ let _ =
560560

561561
let _ =
562562
let x = x in
563-
fun foooooooooooooooooo foooooooooooooooooo foooooooooooooooooo
564-
foooooooooooooooooo foooooooooooooooooo foooooooooooooooooo -> ()
563+
fun foooooooooooooooooo
564+
foooooooooooooooooo
565+
foooooooooooooooooo
566+
foooooooooooooooooo
567+
foooooooooooooooooo
568+
foooooooooooooooooo
569+
-> ()
565570

566571
module type For_let_syntax_local =
567572
For_let_syntax_gen

test/passing/refs.ocamlformat/fun_decl.ml.ref

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ let _ =
8787
let _ =
8888
let _ = () in
8989
fun (context : Context.t)
90-
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t) ->
90+
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t)
91+
->
9192
let _ = () in
9293
()
9394

0 commit comments

Comments
 (0)