Skip to content

Commit bf3f6a4

Browse files
solve issue
1 parent 2644483 commit bf3f6a4

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
@@ -3806,6 +3806,13 @@ and fmt_module_type c ?(rec_ = false) ({ast= mty; _} as xmty) =
38063806
bdy= fmt_longident_loc c lid
38073807
; epi= Some (fmt_attributes c pmty_attributes ~pre:(Break (1, 0))) }
38083808
| Pmty_signature s ->
3809+
let is_signature_multiline =
3810+
match s with
3811+
| [] -> false
3812+
| _ :: _ ->
3813+
(List.hd_exn s).psig_loc.loc_start.pos_lnum
3814+
<> (List.last_exn s).psig_loc.loc_start.pos_lnum
3815+
in
38093816
let empty = List.is_empty s && not (Cmts.has_within c.cmts pmty_loc) in
38103817
let before = Cmts.fmt_before c pmty_loc in
38113818
let within = Cmts.fmt_within c ~pro:noop pmty_loc in
@@ -3820,7 +3827,8 @@ and fmt_module_type c ?(rec_ = false) ({ast= mty; _} as xmty) =
38203827
; cls= noop
38213828
; esp=
38223829
fmt_if (not empty)
3823-
( if c.conf.fmt_opts.break_struct.v then force_break
3830+
( if c.conf.fmt_opts.break_struct.v || is_signature_multiline then
3831+
force_break
38243832
else break 1 0 )
38253833
; epi=
38263834
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)