Skip to content

Commit 253323e

Browse files
authored
Fix ';;' formatting between doc-comments and toplevel directives (#2432)
1 parent c7b89a0 commit 253323e

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Tags:
3131
- Fix dropped attributes on a begin-end in a match case (#2421, @Julow)
3232
- Fix non-stabilizing comments before a functor type argument (#2420, @Julow)
3333
- Fix crash caused by module types with nested `with module` (#2419, @Julow)
34+
- Fix ';;' formatting between doc-comments and toplevel directives (#2432, @gpetiot)
3435

3536
## 0.26.0 (2023-07-18)
3637

lib/Fmt_ast.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4449,6 +4449,7 @@ let fmt_toplevel ?(force_semisemi = false) c ctx itms =
44494449
let semisemi =
44504450
match (itm, next) with
44514451
| _, Some (`Item {pstr_desc= Pstr_eval _; _}, _) -> true
4452+
| `Item {pstr_desc= Pstr_attribute _; _}, _ -> false
44524453
| `Item _, Some (`Directive _, _) -> true
44534454
| _ -> force_semisemi && last
44544455
in

test/passing/dune.inc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,24 @@
15861586
(package ocamlformat)
15871587
(action (diff tests/doc_repl.mld.err doc_repl.mld.stderr)))
15881588

1589+
(rule
1590+
(deps tests/.ocamlformat )
1591+
(package ocamlformat)
1592+
(action
1593+
(with-stdout-to docstrings_toplevel_directives.mlt.stdout
1594+
(with-stderr-to docstrings_toplevel_directives.mlt.stderr
1595+
(run %{bin:ocamlformat} --margin-check %{dep:tests/docstrings_toplevel_directives.mlt})))))
1596+
1597+
(rule
1598+
(alias runtest)
1599+
(package ocamlformat)
1600+
(action (diff tests/docstrings_toplevel_directives.mlt docstrings_toplevel_directives.mlt.stdout)))
1601+
1602+
(rule
1603+
(alias runtest)
1604+
(package ocamlformat)
1605+
(action (diff tests/docstrings_toplevel_directives.mlt.err docstrings_toplevel_directives.mlt.stderr)))
1606+
15891607
(rule
15901608
(deps tests/.ocamlformat )
15911609
(package ocamlformat)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(** Header *)
2+
3+
#use "something"
4+
5+
let two = 2
6+
7+
[@@@warning "-labels-omitted"] ;;
8+
9+
Clflags.strict_sequence := false
10+
11+
let f () = x

0 commit comments

Comments
 (0)