Skip to content

Commit abe4689

Browse files
authored
Don't align breaking module arguments (#2505)
* Don't align module argument types This alignment is not diff-friendly and is elsewhere recognized as a bug. module Make (TT : TableFormat.TABLES) (IT : InspectionTableFormat.TABLES with type 'a lr1state = int) - (ET : EngineTypes.TABLE - with type terminal = int - and type nonterminal = int - and type semantic_value = Obj.t) + (ET : + EngineTypes.TABLE + with type terminal = int + and type nonterminal = int + and type semantic_value = Obj.t) (E : sig type 'a env = (ET.state, ET.semantic_value, ET.token) EngineTypes.env end) =
1 parent fff2016 commit abe4689

File tree

7 files changed

+28
-21
lines changed

7 files changed

+28
-21
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ profile. This started with version 0.26.0.
1616
- \* Janestreet profile: do not break `fun _ -> function` (#2460, @tdelvecchio-jsc)
1717
- \* Reduce the indentation of (polytype) type constraints (#2437, @gpetiot)
1818
- \* Consistent indentation of polymorphic variant arguments (#2427, @Julow)
19+
- \* Don't align breaking module arguments (#2505, @Julow)
1920

2021
### Fixed
2122

lib/Fmt_ast.ml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3820,16 +3820,20 @@ and fmt_module c ctx ?rec_ ?epi ?(can_sparse = false) keyword ?(eqty = "=")
38203820
; psp= fmt_if (Option.is_none blk.pro) "@;<1 2>" $ blk.psp } )
38213821
in
38223822
let blk_b = Option.value_map xbody ~default:empty ~f:(fmt_module_expr c) in
3823+
let args_p = Params.Mod.get_args c.conf xargs in
38233824
let fmt_name_and_mt ~pro ~loc name mt =
38243825
let xmt = sub_mty ~ctx mt in
38253826
let blk = fmt_module_type c ?rec_ xmt in
3827+
let align_opn, align_cls =
3828+
if args_p.align then (open_hvbox 0, close_box) else (noop, noop)
3829+
in
38263830
let pro =
3827-
pro $ Cmts.fmt_before c loc $ str "(" $ fmt_str_loc_opt c name
3828-
$ str " : "
3829-
and epi = str ")" $ Cmts.fmt_after c loc in
3831+
pro $ Cmts.fmt_before c loc $ str "(" $ align_opn
3832+
$ fmt_str_loc_opt c name $ str " :"
3833+
$ fmt_or_k (Option.is_some blk.pro) (str " ") (break 1 2)
3834+
and epi = str ")" $ Cmts.fmt_after c loc $ align_cls in
38303835
compose_module' ~box:false ~pro ~epi blk
38313836
in
3832-
let args_p = Params.Mod.get_args c.conf xargs in
38333837
(* Carry the [epi] to be placed in the next argument's box. *)
38343838
let fmt_arg ~pro {loc; txt} =
38353839
let pro = pro $ args_p.arg_psp in

lib/Params.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ module Mod = struct
123123
else List.for_all ~f:arg_is_sig args
124124
in
125125
let arg_psp = if dock then str " " else break 1 psp_indent in
126-
let align = ocp c in
126+
let align = (not dock) && ocp c in
127127
{dock; arg_psp; indent; align}
128128

129129
let break_constraint c ~rhs =

test/passing/tests/functor.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ module type KV_MAKER = functor (G : Irmin_git.G) (C : Irmin.Contents.S) ->
7171
module Make
7272
(TT : TableFormat.TABLES)
7373
(IT : InspectionTableFormat.TABLES with type 'a lr1state = int)
74-
(ET : EngineTypes.TABLE
75-
with type terminal = int
76-
and type nonterminal = int
77-
and type semantic_value = Obj.t)
74+
(ET :
75+
EngineTypes.TABLE
76+
with type terminal = int
77+
and type nonterminal = int
78+
and type semantic_value = Obj.t)
7879
(E : sig
7980
type 'a env = (ET.state, ET.semantic_value, ET.token) EngineTypes.env
8081
end) =

test/passing/tests/js_source.ml.err

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Warning: tests/js_source.ml:9537 exceeds the margin
33
Warning: tests/js_source.ml:9640 exceeds the margin
44
Warning: tests/js_source.ml:9699 exceeds the margin
55
Warning: tests/js_source.ml:9781 exceeds the margin
6+
Warning: tests/js_source.ml:10290 exceeds the margin

test/passing/tests/js_source.ml.ocp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10287,10 +10287,10 @@ type t =
1028710287

1028810288
module Test_gen
1028910289
(For_tests : For_tests_gen)
10290-
(Tested : S_gen
10291-
with type 'a src := 'a For_tests.Src.t
10292-
with type 'a dst := 'a For_tests.Dst.t)
10293-
(Tested : S_gen
10290+
(Tested :
10291+
S_gen with type 'a src := 'a For_tests.Src.t with type 'a dst := 'a For_tests.Dst.t)
10292+
(Tested :
10293+
S_gen
1029410294
with type 'a src := 'a For_tests.Src.t
1029510295
with type 'a dst := 'a For_tests.Dst.t
1029610296
and type 'a dst := 'a For_tests.Dst.t

test/passing/tests/js_source.ml.ref

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10287,14 +10287,14 @@ type t =
1028710287

1028810288
module Test_gen
1028910289
(For_tests : For_tests_gen)
10290-
(Tested : S_gen
10291-
with type 'a src := 'a For_tests.Src.t
10292-
with type 'a dst := 'a For_tests.Dst.t)
10293-
(Tested : S_gen
10294-
with type 'a src := 'a For_tests.Src.t
10295-
with type 'a dst := 'a For_tests.Dst.t
10296-
and type 'a dst := 'a For_tests.Dst.t
10297-
and type 'a dst := 'a For_tests.Dst.t) =
10290+
(Tested :
10291+
S_gen with type 'a src := 'a For_tests.Src.t with type 'a dst := 'a For_tests.Dst.t)
10292+
(Tested :
10293+
S_gen
10294+
with type 'a src := 'a For_tests.Src.t
10295+
with type 'a dst := 'a For_tests.Dst.t
10296+
and type 'a dst := 'a For_tests.Dst.t
10297+
and type 'a dst := 'a For_tests.Dst.t) =
1029810298
struct
1029910299
open Tested
1030010300
open For_tests

0 commit comments

Comments
 (0)