Skip to content

Commit 42a3e18

Browse files
solve issue
1 parent dcc1e5a commit 42a3e18

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

lib/Fmt_ast.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3803,6 +3803,13 @@ and fmt_module_type c ?(rec_ = false) ({ast= mty; _} as xmty) =
38033803
bdy= fmt_longident_loc c lid
38043804
; epi= Some (fmt_attributes c pmty_attributes ~pre:(Break (1, 0))) }
38053805
| Pmty_signature s ->
3806+
let is_signature_multiline =
3807+
match s with
3808+
| [] -> false
3809+
| _ :: _ ->
3810+
(List.hd_exn s).psig_loc.loc_start.pos_lnum
3811+
<> (List.last_exn s).psig_loc.loc_start.pos_lnum
3812+
in
38063813
let empty = List.is_empty s && not (Cmts.has_within c.cmts pmty_loc) in
38073814
let before = Cmts.fmt_before c pmty_loc in
38083815
let within = Cmts.fmt_within c ~pro:noop pmty_loc in
@@ -3817,7 +3824,8 @@ and fmt_module_type c ?(rec_ = false) ({ast= mty; _} as xmty) =
38173824
; cls= noop
38183825
; esp=
38193826
fmt_if (not empty)
3820-
( if c.conf.fmt_opts.break_struct.v then force_break
3827+
( if c.conf.fmt_opts.break_struct.v || is_signature_multiline then
3828+
force_break
38213829
else break 1 0 )
38223830
; epi=
38233831
Some

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,21 @@ module type Module_type_fail = sig
9494

9595
module F : functor (_ : T) -> sig end
9696

97-
include S end
97+
include S
98+
end
9899

99100
module A : sig
100101
type a
101102

102-
type b end =
103+
type b
104+
end =
103105
B
104106

105107
module A : sig
106108
type a
107109

108-
type b end = struct
110+
type b
111+
end = struct
109112
type a
110113

111114
type b

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,21 @@ module type Module_type_fail = sig
109109

110110
module F : functor (_ : T) -> sig end
111111

112-
include S end
112+
include S
113+
end
113114

114115
module A : sig
115116
type a
116117

117-
type b end =
118+
type b
119+
end =
118120
B
119121

120122
module A : sig
121123
type a
122124

123-
type b end = struct
125+
type b
126+
end = struct
124127
type a
125128

126129
type b

0 commit comments

Comments
 (0)