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

Remove some calls to if_newline and break_unless_newline and fix break before closing brackets #1168

Merged
merged 4 commits into from
Nov 28, 2019
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
+ Fix: types on named arguments were wrapped incorrectly when preceding comments (#1124) (Guillaume Petiot)
+ Fix the indentation produced by max-indent (#1118) (Guillaume Petiot)
+ Fix break after Psig_include depending on presence of docstring (#1125) (Guillaume Petiot)
+ Remove some calls to if_newline and break_unless_newline and fix break before closing brackets (#1168) (Guillaume Petiot)

#### Internal

Expand Down
9 changes: 4 additions & 5 deletions lib/Cmts.ml
Original file line number Diff line number Diff line change
Expand Up @@ -628,18 +628,17 @@ let fmt_cmts t (conf : Conf.t) ~fmt_code ?pro ?epi ?(eol = Fmt.fmt "@\n")
( close_box
$ fmt_or_k eol_cmt (fmt_or_k adj_cmt adj eol) (fmt_opt epi) ))

let fmt_before t conf ~fmt_code ?pro ?(epi = Fmt.break_unless_newline 1 0)
?eol ?adj =
let fmt_before t conf ~fmt_code ?pro ?(epi = Fmt.break 1 0) ?eol ?adj =
fmt_cmts t conf t.cmts_before ~fmt_code ?pro ~epi ?eol ?adj

let fmt_after t conf ~fmt_code ?(pro = Fmt.break_unless_newline 1 0) ?epi =
let fmt_after t conf ~fmt_code ?(pro = Fmt.break 1 0) ?epi =
let open Fmt in
let within = fmt_cmts t conf t.cmts_within ~fmt_code ~pro ?epi in
let after = fmt_cmts t conf t.cmts_after ~fmt_code ~pro ?epi ~eol:noop in
fun loc -> within loc $ after loc

let fmt_within t conf ~fmt_code ?(pro = Fmt.break_unless_newline 1 0)
?(epi = Fmt.break_unless_newline 1 0) =
let fmt_within t conf ~fmt_code ?(pro = Fmt.break 1 0) ?(epi = Fmt.break 1 0)
=
fmt_cmts t conf t.cmts_within ~fmt_code ~pro ~epi ~eol:Fmt.noop

let fmt t conf ~fmt_code ?pro ?epi ?eol ?adj loc =
Expand Down
13 changes: 8 additions & 5 deletions lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ and fmt_pattern c ?pro ?parens ({ctx= ctx0; ast= pat} as xpat) =
(p.box
( list_fl loc_xpats fmt_pat
$ Cmts.fmt_before c ~pro:cmt_break ~epi:noop nil_loc
~eol:noop
$ Cmts.fmt_after c ~pro:(fmt "@ ") ~epi:noop nil_loc )))
| None ->
hvbox 0
Expand Down Expand Up @@ -3165,10 +3166,10 @@ and fmt_type_extension c ctx
$ fmt_longident_loc c ptyext_path
$ str " +="
$ fmt_private_flag ptyext_private
$ fmt "@ "
$ hvbox 0
(if_newline "| " $ list ptyext_constructors "@ | " fmt_ctor)
)
$ list_fl ptyext_constructors (fun ~first ~last:_ x ->
let bar_fits = if first then "" else "| " in
cbreak ~fits:("", 1, bar_fits) ~breaks:("", 0, "| ")
$ fmt_ctor x) )
$ fmt_attributes c ~pre:(fmt "@ ") ~key:"@@" atrs )

and fmt_type_exception ~pre c sep ctx
Expand Down Expand Up @@ -4324,7 +4325,9 @@ let fmt_toplevel c ctx itms =

let fmt_file ~ctx ~f ~fmt_code source cmts conf itms =
let c = {source; cmts; conf; fmt_code} in
match itms with [] -> Cmts.fmt_after c Location.none | l -> f c ctx l
match itms with
| [] -> Cmts.fmt_after ~pro:noop c Location.none
| l -> f c ctx l

let rec fmt_code conf s =
match
Expand Down
3 changes: 1 addition & 2 deletions lib/Params.ml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ let get_cases (c : Conf.t) ~first ~indent ~parens_here =
; break_after_opening_paren= fmt "@ " }

let wrap_collec c ~space_around opn cls =
if space_around then
wrap_k (str opn $ char ' ') (break_unless_newline 1 0 $ str cls)
if space_around then wrap_k (str opn $ char ' ') (break 1 0 $ str cls)
else wrap_fits_breaks c opn cls

let wrap_record (c : Conf.t) =
Expand Down
6 changes: 3 additions & 3 deletions test/passing/list.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ let x = function
"sed do eiusmod tempor incididunt ut labore et dolore"
(* " magna aliqua. Ut enim ad minim veniam, quis nostrud "; *)
(* "exercitation ullamco laboris nisi ut aliquip ex ea commodo " *)
]
]
; (* ", sed do eiusmod tempor incididunt ut labore et dolore"; *)
"sed do eiusmod tempor incididunt ut labore et dolore"
(* " magna aliqua. Ut enim ad minim veniam, quis nostrud "; *)
(* "exercitation ullamco laboris nisi ut aliquip ex ea commodo " *)
] ->
(* "exercitation ullamco laboris nisi ut aliquip ex ea commodo " *) ]
->
()

[@@@ocamlformat "space-around-lists=true"]
Expand Down