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

Consistent docking of argument functions #2291

Merged
merged 4 commits into from
Mar 13, 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: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

### Bug fixes

- Avoid adding breaks inside `~label:(fun` and base the indentation on the label. (#2271, @Julow)
- Avoid adding breaks inside `~label:(fun` and base the indentation on the label. (#2271, #2291, @Julow)
- Fix non-stabilizing comments attached to private/virtual/mutable keywords (#2272, @gpetiot)
- Fix formatting of comments in "disable" chunks (#2279, @gpetiot)

Expand Down
24 changes: 24 additions & 0 deletions lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,30 @@ and fmt_label_arg ?(box = true) ?epi ?parens ?eol c
~pro:(fmt_label lbl ":@;<0 2>")
~box ?epi ?parens xarg )
$ cmts_after )
| (Labelled _ | Optional _), Pexp_fun _ ->
(* Side effects of Cmts.fmt c.cmts before Sugar.fun_ is important. *)
let cmt_before = Cmts.fmt_before c arg.pexp_loc in
let xargs, xbody = Sugar.fun_ c.cmts xarg in
let fmt_cstr, xbody = type_constr_and_body c xbody in
let body =
let box =
match xbody.ast.pexp_desc with
| Pexp_fun _ | Pexp_function _ -> Some false
| _ -> None
in
fmt "@ " $ fmt_expression c ?box xbody
in
hovbox_if box 2
( hvbox 0
( hvbox 2
( hvbox 2 (fmt_label lbl ":" $ cmt_before $ fmt "(fun")
$ fmt "@ "
$ fmt_attributes c arg.pexp_attributes ~suf:" "
$ fmt_fun_args c xargs $ fmt_opt fmt_cstr )
$ fmt "@ ->" )
$ body
$ closing_paren c ~offset:(-2)
$ Cmts.fmt_after c arg.pexp_loc )
| _ ->
let label_sep : s =
if box || c.conf.fmt_opts.wrap_fun_args.v then ":@," else ":"
Expand Down
14 changes: 14 additions & 0 deletions test/passing/tests/eliom_ext.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ let%client () =
(fun () ->
Lwt.async (fun () -> log "Hello from the client to the server!") )

let%client () =
Eliom_client.onload
(* NB The service underlying the server_function isn't available on the
client before loading the page. *) ~foo:(fun () ->
Lwt.async (fun () -> log "Hello from the client to the server!") )

let%client () =
Eliom_client.onload
(* NB The service underlying the server_function isn't available on the
client before loading the page. *)
~foo:(fun () ->
Lwt.async (fun () -> log "Hello from the client to the server!") )
bar

[%%shared
type some_type = int * string list [@@deriving json]

Expand Down
8 changes: 8 additions & 0 deletions test/passing/tests/js_source.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7655,3 +7655,11 @@ let () = ((one_mississippi, two_mississippi, three_mississippi, four_mississippi

let _ = ((match foo with | Bar -> bar | Baz -> baz) : string)
let _ = ((match foo with | Bar -> bar | Baz -> baz) :> string)

let _ =
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
~bbbbbbbbbbbbbbbbbbbbbbbbbbbb:(fun (_ :
(ccccccccccccc * ddddddddddddddddddddddddddddd)
eeee) -> FFFFFFFFF gg)
~h
;;
8 changes: 8 additions & 0 deletions test/passing/tests/js_source.ml.ocp
Original file line number Diff line number Diff line change
Expand Up @@ -9889,3 +9889,11 @@ let _ =
| Baz -> baz)
:> string)
;;

let _ =
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
~bbbbbbbbbbbbbbbbbbbbbbbbbbbb:(fun
(_ : (ccccccccccccc * ddddddddddddddddddddddddddddd) eeee)
-> FFFFFFFFF gg)
~h
;;
8 changes: 8 additions & 0 deletions test/passing/tests/js_source.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -9889,3 +9889,11 @@ let _ =
| Baz -> baz)
:> string)
;;

let _ =
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
~bbbbbbbbbbbbbbbbbbbbbbbbbbbb:(fun
(_ : (ccccccccccccc * ddddddddddddddddddddddddddddd) eeee)
-> FFFFFFFFF gg)
~h
;;