Skip to content

Commit

Permalink
JaneStreet profile: add extra parens around tuple with type annotation (
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetiot authored Mar 9, 2023
1 parent 869ea50 commit fd21b79
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Changes

- JaneStreet profile: add extra parens around tuple with type annotation (#2281, @gpetiot)

### New features

## 0.25.1 (2023-03-06)
Expand Down
15 changes: 13 additions & 2 deletions lib/Ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,28 @@ let ( init
, register_reset
, leading_nested_match_parens
, parens_ite
, ocaml_version ) =
, ocaml_version
, ocp_indent_compat ) =
let l = ref [] in
let leading_nested_match_parens = ref false in
let parens_ite = ref false in
let ocaml_version = ref Ocaml_version.sys_version in
let ocp_indent_compat = ref false in
let register f = l := f :: !l in
let init (conf : Conf.t) =
leading_nested_match_parens :=
conf.fmt_opts.leading_nested_match_parens.v ;
parens_ite := conf.fmt_opts.parens_ite.v ;
ocaml_version := conf.opr_opts.ocaml_version.v ;
ocp_indent_compat := conf.fmt_opts.ocp_indent_compat.v ;
List.iter !l ~f:(fun f -> f ())
in
(init, register, leading_nested_match_parens, parens_ite, ocaml_version)
( init
, register
, leading_nested_match_parens
, parens_ite
, ocaml_version
, ocp_indent_compat )

(** [fit_margin c x] returns [true] if and only if [x] does not exceed 1/3 of
the margin. *)
Expand Down Expand Up @@ -2174,6 +2182,9 @@ end = struct
| Exp {pexp_desc= Pexp_indexop_access {pia_kind= Builtin idx; _}; _}, _
when idx == exp ->
false
| Exp {pexp_desc= Pexp_constraint (e, _); _}, {pexp_desc= Pexp_tuple _; _}
when e == exp && !ocp_indent_compat ->
true
| ( Exp
{ pexp_desc=
Pexp_indexop_access
Expand Down
2 changes: 2 additions & 0 deletions test/passing/tests/js_source.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7650,3 +7650,5 @@ let () =
very_long_argument_name_two
very_long_argument_name_three
-> () )

let () = ((one_mississippi, two_mississippi, three_mississippi, four_mississippi) : Mississippi.t * Mississippi.t * Mississippi.t * Mississippi.t)
5 changes: 5 additions & 0 deletions test/passing/tests/js_source.ml.ocp
Original file line number Diff line number Diff line change
Expand Up @@ -9874,3 +9874,8 @@ let () =
very_long_argument_name_three
-> ())
;;

let () =
((one_mississippi, two_mississippi, three_mississippi, four_mississippi)
: Mississippi.t * Mississippi.t * Mississippi.t * Mississippi.t)
;;
5 changes: 5 additions & 0 deletions test/passing/tests/js_source.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -9874,3 +9874,8 @@ let () =
very_long_argument_name_three
-> ())
;;

let () =
((one_mississippi, two_mississippi, three_mississippi, four_mississippi)
: Mississippi.t * Mississippi.t * Mississippi.t * Mississippi.t)
;;

0 comments on commit fd21b79

Please sign in to comment.