Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JaneStreet profile: add extra parens around tuple with type annotation #2281

Merged
merged 3 commits into from
Mar 9, 2023
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
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)
;;