Skip to content

Commit 66cada7

Browse files
authored
Fix regressions of list element comments (ocaml-ppx#1876)
1 parent 6833734 commit 66cada7

7 files changed

+22
-14
lines changed

CHANGES.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@
5454

5555
+ Set 'module-item-spacing=compact' in the default/conventional profile (#1848, @gpetiot)
5656

57-
+ Preserve bracketed lists in the Parsetree (#1694, @gpetiot)
58-
Comments are now wrapped around list elements instead of causing a break.
57+
+ Preserve bracketed lists in the Parsetree (#1694, #1876, @gpetiot)
5958

6059
+ Line directives now cause OCamlFormat to emit an error, they were previously silently ignored (#1845, @gpetiot)
6160

lib/Fmt_ast.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,14 +1967,15 @@ and fmt_expression c ?(box = true) ?pro ?epi ?eol ?parens ?(indent_wrap = 0)
19671967
$ fmt_atrs )
19681968
| Pexp_list e1N ->
19691969
let p = Params.get_list_expr c.conf in
1970+
let offset = if c.conf.dock_collection_brackets then 0 else 2 in
1971+
let cmt_break = break 1 offset in
19701972
hvbox_if has_attr 0
19711973
(Params.parens_if parens c.conf
19721974
( p.box
19731975
(fmt_expressions c (expression_width c) (sub_exp ~ctx) e1N
19741976
(fun e ->
1975-
let fmt_cmts = Cmts.fmt c ~eol:(break 1 0) e.pexp_loc in
1976-
hvbox 0 @@ fmt_cmts
1977-
@@ (sub_exp ~ctx >> fmt_expression c) e )
1977+
let fmt_cmts = Cmts.fmt c ~eol:cmt_break e.pexp_loc in
1978+
fmt_cmts @@ (sub_exp ~ctx >> fmt_expression c) e )
19781979
p )
19791980
$ fmt_atrs ) )
19801981
| Pexp_assert e0 ->

test/passing/tests/break_separators-after.ml.ref

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ let length =
167167
let length =
168168
[ 0;
169169
14;
170-
(* foo *) 14;
170+
(* foo *)
171+
14;
171172
17 (* foo *);
172173
17;
173174
2777777777777777777777777777777777;
@@ -309,7 +310,8 @@ let length =
309310
14;
310311
14;
311312
14;
312-
(* foo *) 14;
313+
(* foo *)
314+
14;
313315
15;
314316
15;
315317
15;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Warning: tests/break_separators.ml:571 exceeds the margin
1+
Warning: tests/break_separators.ml:573 exceeds the margin

test/passing/tests/break_separators-after_docked.ml.ref

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ let length =
189189
[
190190
0;
191191
14;
192-
(* foo *) 14;
192+
(* foo *)
193+
14;
193194
17 (* foo *);
194195
17;
195196
2777777777777777777777777777777777;
@@ -337,7 +338,8 @@ let length =
337338
14;
338339
14;
339340
14;
340-
(* foo *) 14;
341+
(* foo *)
342+
14;
341343
15;
342344
15;
343345
15;

test/passing/tests/break_separators-before_docked.ml.ref

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ let length =
189189
[
190190
0
191191
; 14
192-
; (* foo *) 14
192+
; (* foo *)
193+
14
193194
; 17 (* foo *)
194195
; 17
195196
; 2777777777777777777777777777777777
@@ -337,7 +338,8 @@ let length =
337338
; 14
338339
; 14
339340
; 14
340-
; (* foo *) 14
341+
; (* foo *)
342+
14
341343
; 15
342344
; 15
343345
; 15

test/passing/tests/break_separators.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ let length =
167167
let length =
168168
[ 0
169169
; 14
170-
; (* foo *) 14
170+
; (* foo *)
171+
14
171172
; 17 (* foo *)
172173
; 17
173174
; 2777777777777777777777777777777777
@@ -309,7 +310,8 @@ let length =
309310
; 14
310311
; 14
311312
; 14
312-
; (* foo *) 14
313+
; (* foo *)
314+
14
313315
; 15
314316
; 15
315317
; 15

0 commit comments

Comments
 (0)