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 formatting of module types #2395

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1bf4b04
ocp-indent-compat: Align module arguments
Julow May 10, 2023
2e50162
Update CHANGES
Julow May 10, 2023
53421df
Merge branch 'main' into ocp-mty-align
Julow May 22, 2023
d5a4f37
WIP
Julow May 15, 2023
f3f887f
Fix formatting of includes, pmod_with, functor
Julow May 22, 2023
544d416
Docked/wrapped module args
Julow May 23, 2023
daedfda
fmt
Julow May 23, 2023
706259c
Fix placement of comments around module arguments
Julow May 23, 2023
1aa8e28
Parens around module type expr of rec module decl
Julow May 23, 2023
c63dfc6
Remove unecessary parentheses around Pmty_with
Julow May 24, 2023
dfdba8e
Restore docking of functor arguments
Julow May 24, 2023
1c97787
Restore break between `= struct` in some cases
Julow May 24, 2023
591ddb8
Restore formatting of module arguments
Julow May 24, 2023
a38db96
Remove parenthesis around functor types with attributes
Julow May 24, 2023
1641a65
Break before module type that follow breaking arguments
Julow May 24, 2023
01cf935
Accept changed formatting of module with constraints
Julow May 24, 2023
e78c454
Dock large module type expr after a functor
Julow May 24, 2023
967fcb3
Merge branch 'MAIN' into rewrite-fmt-mt
Julow Jul 5, 2023
0955f0a
Avoid breaking before attributes of a sig
Julow Jul 5, 2023
169d3e4
Restore tests lost after merge
Julow Jul 5, 2023
1404164
Restore docking of module type of struct
Julow Jul 5, 2023
b803db2
Restore formatting of 'sig ... end with ...'
Julow Jul 6, 2023
9d72f4c
Fix indentation of sig of modules with args
Julow Jul 6, 2023
b7f734f
Dock sig after module arguments
Julow Jul 6, 2023
0fa1dac
Update CHANGES
Julow Jul 6, 2023
30dd49c
Consistency between module args and functor exprs
Julow Jul 6, 2023
11d7f16
Indent Pmod_functor
Julow Jul 6, 2023
4f570c0
ocp-indent-compat: Don't dock Pmty_functor
Julow Jul 18, 2023
759a7ae
Merge branch 'main' into rewrite-fmt-mt
Julow Jul 18, 2023
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 @@ -13,7 +13,6 @@
- Protect match after `fun _ : _ ->` (#2352, @Julow)
- Fix invalid formatting of `(::)` (#2347, @Julow)
- Fix formatting of string literals in code blocks (#2338, #2349, @Julow)
- Improve formatting of module arguments (#2322, @Julow)
- Consistent indentation of `@@ let+ x = ...` (#2315, @Julow)
- Remove double parenthesis around tuple in a match (#2308, @Julow)
- Consistent indentation of `fun (type a) ->` that follow `fun x ->` (#2294, @Julow)
Expand All @@ -27,6 +26,7 @@

### Changes

- More consistent formatting of module types (#2322, #2395, @Julow)
- Improve formatting of doc-comments (#2376, #2377, #2379, #2378, @Julow)
- Disable reporting of deprecated alerts while formatting code blocks (#2373, @Julow)
- Improve indentation of `as`-patterns (#2359, @Julow)
Expand Down
33 changes: 14 additions & 19 deletions lib-rpc/protocol.mli
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,18 @@ module Make (IO : IO.S) : sig
end

(** Version used to set the protocol version *)
module Init :
Command_S with type t = [`Halt | `Unknown | `Version of string]

module V1 :
Command_S
with type t =
[ `Halt
| `Unknown
| `Error of string
| `Config of (string * string) list
| `Format of string ]

module V2 :
Command_S
with type t =
[ `Halt
| `Unknown
| `Error of string
| `Format of string * format_args ]
module Init : Command_S
with type t = [`Halt | `Unknown | `Version of string]

module V1 : Command_S
with type t =
[ `Halt
| `Unknown
| `Error of string
| `Config of (string * string) list
| `Format of string ]

module V2 : Command_S
with type t =
[`Halt | `Unknown | `Error of string | `Format of string * format_args]
end
21 changes: 15 additions & 6 deletions lib/Ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ module T = struct
| Exp of expression
| Lb of let_binding
| Mb of module_binding
| Md of module_declaration
| Md of module_declaration * bool (** Recursive *)
| Cl of class_expr
| Mty of module_type
| Mod of module_expr
Expand All @@ -645,7 +645,7 @@ module T = struct
| Exp e -> Format.fprintf fs "Exp:@\n%a" Printast.expression e
| Lb b -> Format.fprintf fs "Lb:@\n%a" Printast.let_binding b
| Mb m -> Format.fprintf fs "Mb:@\n%a" Printast.module_binding m
| Md m -> Format.fprintf fs "Md:@\n%a" Printast.module_declaration m
| Md (m, _) -> Format.fprintf fs "Md:@\n%a" Printast.module_declaration m
| Cl cl -> Format.fprintf fs "Cl:@\n%a" Printast.class_expr cl
| Mty mt -> Format.fprintf fs "Mty:@\n%a" Printast.module_type mt
| Cty cty -> Format.fprintf fs "Cty:@\n%a" Printast.class_type cty
Expand Down Expand Up @@ -675,7 +675,7 @@ let attributes = function
| Exp x -> x.pexp_attributes
| Lb x -> x.lb_attributes
| Mb x -> x.pmb_attributes
| Md x -> x.pmd_attributes
| Md (x, _) -> x.pmd_attributes
| Cl x -> x.pcl_attributes
| Mty x -> x.pmty_attributes
| Mod x -> x.pmod_attributes
Expand All @@ -696,7 +696,7 @@ let location = function
| Exp x -> x.pexp_loc
| Lb x -> x.lb_loc
| Mb x -> x.pmb_loc
| Md x -> x.pmd_loc
| Md (x, _) -> x.pmd_loc
| Cl x -> x.pcl_loc
| Mty x -> x.pmty_loc
| Mod x -> x.pmod_loc
Expand Down Expand Up @@ -725,7 +725,7 @@ let break_between s cc (i1, c1) (i2, c2) =
| Sig i1, Sig i2 -> Signature_item.break_between s cc (i1, c1) (i2, c2)
| Lb i1, Lb i2 -> Lb.break_between s cc (i1, c1) (i2, c2)
| Mb i1, Mb i2 -> Mb.break_between s cc (i1, c1) (i2, c2)
| Md i1, Md i2 -> Md.break_between s cc (i1, c1) (i2, c2)
| Md (i1, _), Md (i2, _) -> Md.break_between s cc (i1, c1) (i2, c2)
| Mty _, Mty _ -> break_between_modules s cc (i1, c1) (i2, c2)
| Mod _, Mod _ -> break_between_modules s cc (i1, c1) (i2, c2)
| Tli (`Item i1), Tli (`Item i2) ->
Expand Down Expand Up @@ -1781,7 +1781,16 @@ end = struct

(** [parenze_mty {ctx; ast}] holds when module type [ast] should be
parenthesized in context [ctx]. *)
let parenze_mty {ctx= _; ast= mty} = Mty.has_trailing_attributes mty
let parenze_mty {ctx; ast= mty} =
match (ctx, mty.pmty_desc) with
| _, (Pmty_ident _ | Pmty_extension _ | Pmty_signature _) -> false
(* Currently, attributes on a [Pmty_functor] are always in short form. *)
| _, Pmty_functor _ -> false
(* [Pmty_with] must be parenthesed when on the RHS of a module decl
followed by an [and]. This is an over-approximation. *)
| Md (_, true), Pmty_with _ -> true
| (Str _ | Sig _), _ -> false
| _ -> Mty.has_trailing_attributes mty

(** [parenze_mod {ctx; ast}] holds when module expr [ast] should be
parenthesized in context [ctx]. *)
Expand Down
2 changes: 1 addition & 1 deletion lib/Ast.mli
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ type t =
| Exp of expression
| Lb of let_binding
| Mb of module_binding
| Md of module_declaration
| Md of module_declaration * bool (** Recursive *)
| Cl of class_expr
| Mty of module_type
| Mod of module_expr
Expand Down
Loading