Skip to content

Commit

Permalink
Preserve line break between operator and let (#2396)
Browse files Browse the repository at this point in the history
* Preserve line break between operator and let

`@@ let` used to always break while `@@ let+` used to always align.
This was changed in 913f754 to always break in both cases for
consistency.

Now, the break is preserved except in the case of a plain `let`.
Preserving the line break on `let` do not reduce the regressions with
the previous version and unecessarily give more use cases to this
unwanted feature.

This applies to `let<op>`, `let exception` and `let module`.
  • Loading branch information
Julow authored Jul 10, 2023
1 parent cea4c4e commit 14347a3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 40 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
- Fix invalid formatting of `(::)` (#2347, @Julow)
- Fix formatting of string literals in code blocks (#2338, #2349, @Julow)
- Improve formatting of module arguments (#2322, @Julow)
- Consistent indentation of `@@ let+ x = ...` (#2315, @Julow)
- Consistent indentation of `@@ let+ x = ...` (#2315, #2396, @Julow)
- Remove double parenthesis around tuple in a match (#2308, @Julow)
- Consistent indentation of `fun (type a) ->` that follow `fun x ->` (#2294, @Julow)
- Avoid adding breaks inside `~label:(fun` and base the indentation on the label. (#2271, #2291, #2293, #2298, @Julow)
Expand Down
10 changes: 7 additions & 3 deletions lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1540,9 +1540,13 @@ and fmt_infix_op_args c ~parens xexp op_args =
in
let is_not_indented {ast= exp; _} =
match exp.pexp_desc with
| Pexp_ifthenelse _ | Pexp_let _ | Pexp_letop _ | Pexp_letexception _
|Pexp_letmodule _ | Pexp_match _ | Pexp_newtype _ | Pexp_sequence _
|Pexp_try _ | Pexp_letopen _ ->
| Pexp_letop _ | Pexp_letexception _ | Pexp_letmodule _ ->
(* In 0.25.1 and before, these used to not break and were aligned at
the end of the operator. Preserve the break to avoid introducing
large diffs while allowing consistent formatting. *)
Source.begins_line c.source exp.pexp_loc
| Pexp_ifthenelse _ | Pexp_let _ | Pexp_match _ | Pexp_newtype _
|Pexp_sequence _ | Pexp_try _ | Pexp_letopen _ ->
true
| _ -> false
in
Expand Down
23 changes: 11 additions & 12 deletions test/passing/tests/break_infix-fit-or-vertical.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,17 @@ let _ =

let term =
Term.ret
@@
let+ config = Common.config_term
and+ mode =
Arg.(
value
& pos 0 (some (enum modes)) None
& info [] ~docv:"ACTION"
~doc:
(Printf.sprintf "The cache-daemon action to perform (%s)"
(Arg.doc_alts_enum modes) ) )
in
(config, mode)
@@ let+ config = Common.config_term
and+ mode =
Arg.(
value
& pos 0 (some (enum modes)) None
& info [] ~docv:"ACTION"
~doc:
(Printf.sprintf "The cache-daemon action to perform (%s)"
(Arg.doc_alts_enum modes) ) )
in
(config, mode)

let term =
Term.ret
Expand Down
23 changes: 11 additions & 12 deletions test/passing/tests/break_infix-wrap.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,17 @@ let _ =

let term =
Term.ret
@@
let+ config = Common.config_term
and+ mode =
Arg.(
value
& pos 0 (some (enum modes)) None
& info [] ~docv:"ACTION"
~doc:
(Printf.sprintf "The cache-daemon action to perform (%s)"
(Arg.doc_alts_enum modes) ) )
in
(config, mode)
@@ let+ config = Common.config_term
and+ mode =
Arg.(
value
& pos 0 (some (enum modes)) None
& info [] ~docv:"ACTION"
~doc:
(Printf.sprintf "The cache-daemon action to perform (%s)"
(Arg.doc_alts_enum modes) ) )
in
(config, mode)

let term =
Term.ret
Expand Down
23 changes: 11 additions & 12 deletions test/passing/tests/break_infix.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,17 @@ let _ =

let term =
Term.ret
@@
let+ config = Common.config_term
and+ mode =
Arg.(
value
& pos 0 (some (enum modes)) None
& info [] ~docv:"ACTION"
~doc:
(Printf.sprintf "The cache-daemon action to perform (%s)"
(Arg.doc_alts_enum modes) ) )
in
(config, mode)
@@ let+ config = Common.config_term
and+ mode =
Arg.(
value
& pos 0 (some (enum modes)) None
& info [] ~docv:"ACTION"
~doc:
(Printf.sprintf "The cache-daemon action to perform (%s)"
(Arg.doc_alts_enum modes) ) )
in
(config, mode)

let term =
Term.ret
Expand Down

0 comments on commit 14347a3

Please sign in to comment.