Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,43 @@ profile. This started with version 0.26.0.

- Fix dropped comment in `(function _ -> x (* cmt *))` (#2739, @Julow)

- \* `cases-matching-exp-indent=compact` does not impact `begin end` nodes that
don't have a match inside. (#2742, @EmileTrotignon)
```ocaml
(* before *)
begin match () with
| () -> begin
f x
end
end
(* after *)
begin match () with
| () -> begin
f x
end
end
```


### Changed

- indentation of the `end` keyword in a match-case is now always at least 2. (#2742, @EmileTrotignon)
```ocaml
(* before *)
begin match () with
| () -> begin
match () with
| () -> ()
end
end
(* after *)
begin match () with
| () -> begin
match () with
| () -> ()
end
end
```
## 0.28.1

### Highlight
Expand Down Expand Up @@ -38,7 +75,7 @@ profile. This started with version 0.26.0.
### Added

- Added option `module-indent` option (#2711, @HPRIOR) to control the indentation
of items within modules. This affects modules and signatures. For example,
of items within modules. This affects modules and signatures. For example,
module-indent=4:
```ocaml
module type M = sig
Expand Down Expand Up @@ -146,7 +183,7 @@ profile. This started with version 0.26.0.
- Fix a crash where `type%e nonrec t = t` was formatted as `type nonrec%e t = t`,
which is invalid syntax. (#2712, @EmileTrotignon)

- Fix commandline parsing being quadratic in the number of arguments
- Fix commandline parsing being quadratic in the number of arguments
(#2724, @let-def)

- \* Fix `;;` being added after a documentation comment (#2683, @EmileTrotignon)
Expand Down
8 changes: 4 additions & 4 deletions lib/Params.ml
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,9 @@ let get_cases (c : Conf.t) ~fmt_infix_ext_attrs ~ctx ~first ~last
Pexp_function _ | Pexp_match _ | Pexp_try _ | Pexp_let _
; _ }
| Lb {pvb_body= Pfunction_cases _; _} )
, (Pexp_match _ | Pexp_try _ | Pexp_beginend _) ) ) ->
, ( Pexp_match _ | Pexp_try _
| Pexp_beginend ({pexp_desc= Pexp_match _ | Pexp_try _; _}, _) ) )
) ->
2
| _, _ -> c.fmt_opts.cases_exp_indent.v
in
Expand Down Expand Up @@ -542,9 +544,7 @@ let get_cases (c : Conf.t) ~fmt_infix_ext_attrs ~ctx ~first ~last
; _ }
when not cmts_before ->
let close_paren =
let offset =
match c.fmt_opts.break_cases.v with `Nested -> 0 | _ -> -2
in
let offset = if indent >= 2 then 2 - indent else 0 in
fits_breaks " end" ~level:1 ~hint:(1000, offset) "end"
in
( break 1 0 $ fmt_infix_ext_attrs ~pro:(str "begin") infix_ext_attrs
Expand Down
18 changes: 18 additions & 0 deletions test/passing/gen/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,24 @@
(package ocamlformat)
(action (diff cases_exp_grouping.ml.err cases_exp_grouping.ml.stderr)))

(rule
(deps .ocamlformat)
(package ocamlformat)
(action
(with-stdout-to cases_exp_indent.ml.stdout
(with-stderr-to cases_exp_indent.ml.stderr
(run %{bin:ocamlformat} --name cases_exp_indent.ml --margin-check --nested-match=align --cases-exp-indent=4 %{dep:../tests/cases_exp_indent.ml})))))

(rule
(alias runtest)
(package ocamlformat)
(action (diff cases_exp_indent.ml.ref cases_exp_indent.ml.stdout)))

(rule
(alias runtest)
(package ocamlformat)
(action (diff cases_exp_indent.ml.err cases_exp_indent.ml.stderr)))

(rule
(deps .ocamlformat)
(enabled_if (<> %{os_type} Win32))
Expand Down
20 changes: 10 additions & 10 deletions test/passing/refs.ahrefs/cases_exp_grouping.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let _ =
| B -> fooooooooooooo
| C -> fooooooooooooo
| D -> fooooooooooooo
end
end
[@@ocamlformat "break-cases=fit"]

let _ =
Expand Down Expand Up @@ -37,59 +37,59 @@ let _ =
| A -> begin
match B with
| A -> fooooooooooooo
end
end
| A -> begin
match B with
| A -> fooooooooooooo
| B -> fooooooooooooo
end
end
| A -> begin
match B with
| A -> fooooooooooooo
| B -> fooooooooooooo
| C -> fooooooooooooo
| D -> fooooooooooooo
end
end
[@@ocamlformat "break-cases=toplevel"]

let _ =
match x with
| A -> begin
match B with
| A -> fooooooooooooo
end
end
| A -> begin
match B with
| A -> fooooooooooooo
| B -> fooooooooooooo
end
end
| A -> begin
match B with
| A -> fooooooooooooo
| B -> fooooooooooooo
| C -> fooooooooooooo
| D -> fooooooooooooo
end
end
[@@ocamlformat "break-cases=fit-or-vertical"]

let _ =
match x with
| A -> begin
match B with
| A -> fooooooooooooo
end
end
| A -> begin
match B with
| A -> fooooooooooooo
| B -> fooooooooooooo
end
end
| A -> begin
match B with
| A -> fooooooooooooo
| B -> fooooooooooooo
| C -> fooooooooooooo
| D -> fooooooooooooo
end
end
[@@ocamlformat "break-cases=all"]

let a =
Expand Down
23 changes: 23 additions & 0 deletions test/passing/refs.ahrefs/cases_exp_indent.ml.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[@@@ocamlformat "break-cases=fit-or-vertical"]

let () =
begin match () with
| () -> begin
aaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaa aaaaaaaaaaaa
aaaaaaaaaaaaa ()
end
| () ->
aaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaa aaaaaaaaaaaa
aaaaaaaaaaaaa ()
| () -> begin
match () with
| () -> ()
end
| () ->
(match () with
| () -> ())
| () -> begin
match () with
| () -> ()
end
end
2 changes: 1 addition & 1 deletion test/passing/refs.ahrefs/effects.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let run (main : unit -> unit) : unit =
| None ->
exchanger := Some (n, k);
dequeue ()
end
end
in
spawn main

Expand Down
6 changes: 3 additions & 3 deletions test/passing/refs.ahrefs/exp_grouping.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,19 @@ let _ =
| A -> begin
match B with
| A -> fooooooooooooo
end
end
| A -> begin
match B with
| A -> fooooooooooooo
| B -> fooooooooooooo
end
end
| A -> begin
match B with
| A -> fooooooooooooo
| B -> fooooooooooooo
| C -> fooooooooooooo
| D -> fooooooooooooo
end
end

let () =
begin
Expand Down
2 changes: 1 addition & 1 deletion test/passing/refs.ahrefs/js_begin.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let f = function
| zoo -> begin
foo;
bar
end
end
let g = function
| zoo ->
foo;
Expand Down
Loading