Skip to content

Commit ed7efe7

Browse files
committed
ocp-indent-compat: Align fun decl arguments
1 parent 138e0bd commit ed7efe7

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

Diff for: lib/Fmt_ast.ml

+15-14
Original file line numberDiff line numberDiff line change
@@ -4304,6 +4304,20 @@ and fmt_value_binding c ~rec_flag ?ext ?in_ ?epi ctx
43044304
, Cmts.Toplevel.fmt_before c lb_loc
43054305
, Cmts.Toplevel.fmt_after c lb_loc )
43064306
in
4307+
let decl_args =
4308+
let decl =
4309+
fmt_str_loc c lb_op
4310+
$ fmt_extension_suffix c ext
4311+
$ fmt_attributes c at_attrs $ fmt_if rec_flag " rec"
4312+
$ fmt_or pat_has_cmt "@ " " "
4313+
and pattern = fmt_pattern c lb_pat
4314+
and args =
4315+
fmt_if_k
4316+
(not (List.is_empty xargs))
4317+
(fmt "@ " $ wrap_fun_decl_args c (fmt_fun_args c xargs))
4318+
in
4319+
box_fun_decl_args c 4 (Params.Align.fun_decl c.conf ~decl ~pattern ~args)
4320+
in
43074321
fmt_docstring c ~epi:(fmt "@\n") doc1
43084322
$ cmts_before
43094323
$ hvbox 0
@@ -4312,20 +4326,7 @@ and fmt_value_binding c ~rec_flag ?ext ?in_ ?epi ctx
43124326
( hvbox_if toplevel indent
43134327
( hovbox 2
43144328
( hovbox (Indent.fun_type_annot c)
4315-
( box_fun_decl_args c (Indent.fun_args c)
4316-
( hovbox 4
4317-
( fmt_str_loc c lb_op
4318-
$ fmt_extension_suffix c ext
4319-
$ fmt_attributes c at_attrs
4320-
$ fmt_if rec_flag " rec"
4321-
$ fmt_or pat_has_cmt "@ " " "
4322-
$ fmt_pattern c lb_pat )
4323-
$ fmt_if_k
4324-
(not (List.is_empty xargs))
4325-
( fmt "@ "
4326-
$ wrap_fun_decl_args c
4327-
(fmt_fun_args c xargs) ) )
4328-
$ fmt_cstr )
4329+
(decl_args $ fmt_cstr)
43294330
$ fmt_if_k (not lb_pun)
43304331
(fmt_or_k c.conf.fmt_opts.ocp_indent_compat.v
43314332
(fits_breaks " =" ~hint:(1000, 0) "=")

Diff for: lib/Params.ml

+5
Original file line numberDiff line numberDiff line change
@@ -579,4 +579,9 @@ module Align = struct
579579
| _ -> parens && not c.fmt_opts.align_symbol_open_paren.v
580580
in
581581
hvbox_if align 0 t
582+
583+
let fun_decl (c : Conf.t) ~decl ~pattern ~args =
584+
if c.fmt_opts.ocp_indent_compat.v then
585+
hovbox 4 (decl $ hvbox 2 (pattern $ args))
586+
else hovbox 4 (decl $ pattern) $ args
582587
end

Diff for: lib/Params.mli

+2
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,6 @@ module Align : sig
154154

155155
val function_ :
156156
Conf.t -> parens:bool -> ctx0:Ast.t -> self:expression -> Fmt.t -> Fmt.t
157+
158+
val fun_decl : Conf.t -> decl:Fmt.t -> pattern:Fmt.t -> args:Fmt.t -> Fmt.t
157159
end

Diff for: test/passing/tests/js_source.ml.ref

+6-6
Original file line numberDiff line numberDiff line change
@@ -9919,12 +9919,12 @@ type t =
99199919
}
99209920

99219921
let rec collect_files
9922-
~enable_outside_detected_project
9923-
~root
9924-
~segs
9925-
~ignores
9926-
~enables
9927-
~files
9922+
~enable_outside_detected_project
9923+
~root
9924+
~segs
9925+
~ignores
9926+
~enables
9927+
~files
99289928
=
99299929
match segs with
99309930
| [] | [ "" ] -> ignores, enables, files, None

0 commit comments

Comments
 (0)