@@ -2887,11 +2887,12 @@ and fmt_apply c ~e1N1 ~parens ~pro ~ctx ~e0 ~pexp_loc ~pexp_attributes
28872887 | Pexp_beginend
28882888 ( { pexp_desc= Pexp_function (largs, ltyp, lbody)
28892889 ; pexp_attributes= attrs_beginend
2890+ ; pexp_loc
28902891 ; _ } as e_func ) ->
28912892 fmt_apply_last_arg_function c ~last_arg ~lbody ~parens ~intro_epi
28922893 ~pexp_loc ~lbl ~ctx ~largs ~has_attr ~expr_epi ~fmt_atrs ~ltyp ~e0
28932894 ~fmt_args_grouped ~args_before ~wrap
2894- ~beginend: (Some (attrs_beginend, Exp e_func))
2895+ ~beginend: (Some (attrs_beginend, pexp_loc, Exp e_func))
28952896 | _ ->
28962897 let fmt_atrs = fmt_attributes c ~pre: (Break (1 , - 2 )) pexp_attributes in
28972898 let force =
@@ -2930,18 +2931,24 @@ and fmt_apply_last_arg_function c ~last_arg ~lbody ~parens ~intro_epi
29302931 if Location. is_single_line pexp_loc c.conf.fmt_opts.margin.v then Fit
29312932 else Break
29322933 in
2933- let break_end =
2934- let indent =
2935- match (largs, lbody) with [] , Pfunction_cases _ -> 0 | _ -> - 2
2936- in
2937- break 1000 indent
2938- in
29392934 let pro, inner_ctx, end_ =
29402935 match beginend with
29412936 | None -> (noop, inner_ctx, noop)
2942- | Some (attrs , inner_ctx ) ->
2937+ | Some (attrs , pexp_loc , inner_ctx ) ->
2938+ let break_end =
2939+ let indent =
2940+ match (largs, lbody) with
2941+ | [] , Pfunction_cases _ -> 0
2942+ | _ -> - 2
2943+ in
2944+ break 1000 indent
2945+ in
2946+ let cmts_begin = Cmts. fmt_before c pexp_loc in
2947+ let cmts_end = Cmts. fmt_after c pexp_loc in
29432948 let fmt_atrs = fmt_attributes c ~pre: Space attrs in
2944- (str " begin" $ fmt_atrs $ str " " , inner_ctx, break_end $ str " end" )
2949+ ( str " begin" $ fmt_atrs $ str " " $ cmts_begin
2950+ , inner_ctx
2951+ , cmts_end $ break_end $ str " end" )
29452952 in
29462953 (* bookmark *)
29472954 fmt_function ~pro ~last_arg: true ~force_closing_paren ~ctx: inner_ctx
0 commit comments