Skip to content

Commit

Permalink
Improve printing of modules types with one line inside (#2709)
Browse files Browse the repository at this point in the history
* improve printing of modules with one line

* add history entry
  • Loading branch information
SanderSpies authored Apr 17, 2023
1 parent c6817db commit 229ffdf
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 20 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 3.9 (unreleased)

- Print module type body on separate line (@SanderSpies) [#2709](https://github.com/reasonml/reason/pull/2709)
- Fix missing patterns around contraint pattern (a pattern with a type annotation).
- Fix top level extension printing
- Remove the dependency on the `result` package, which isn't needed for OCaml
Expand Down
2 changes: 1 addition & 1 deletion src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7419,7 +7419,7 @@ let printer = object(self:'self)
~comments:self#comments
s
in
let shouldBreakLabel = if List.length s > 1 then `Always else `Auto in
let shouldBreakLabel = if List.length s > 0 then `Always else `Auto in
label
~indent:0
~break:shouldBreakLabel
Expand Down
28 changes: 21 additions & 7 deletions test/modules.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ Format modules
tmp + 30;
};

module type HasTT = {type tt;};
module type HasTT = {
type tt;
};

module SubModule: HasTT = {
type tt = int;
Expand All @@ -123,7 +125,9 @@ Format modules
module SubModuleThatHasTT = SubModule;
};

module type HasPolyType = {type t('a);};
module type HasPolyType = {
type t('a);
};
module type HasDestructivelySubstitutedPolyType =
HasPolyType with type t('a) := list('a);
Expand Down Expand Up @@ -200,10 +204,16 @@ Format modules
type tt = string;
});
module type SigResult = {let result: int;};
module type SigResult = {
let result: int;
};
module type ASig = {let a: int;};
module type BSig = {let b: int;};
module type ASig = {
let a: int;
};
module type BSig = {
let b: int;
};
module AMod = {
let a = 10;
};
Expand Down Expand Up @@ -422,7 +432,9 @@ Format modules
};

/* From http://stackoverflow.com/questions/1986374/higher-order-type-constructors-and-functors-in-ocaml */
module type Type = {type t;};
module type Type = {
type t;
};
module Char = {
type t = char;
};
Expand Down Expand Up @@ -483,7 +495,9 @@ Format modules
let myValue = {recordField: "hello"};
});

module type HasInt = {let x: int;};
module type HasInt = {
let x: int;
};

module MyModule = {
let x = 10;
Expand Down
28 changes: 21 additions & 7 deletions test/modules_no_semi.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ Format modules no semi
tmp + 30;
};

module type HasTT = {type tt;};
module type HasTT = {
type tt;
};

module SubModule: HasTT = {
type tt = int;
Expand All @@ -123,7 +125,9 @@ Format modules no semi
module SubModuleThatHasTT = SubModule;
};

module type HasPolyType = {type t('a);};
module type HasPolyType = {
type t('a);
};
module type HasDestructivelySubstitutedPolyType =
HasPolyType with type t('a) := list('a);
Expand Down Expand Up @@ -200,10 +204,16 @@ Format modules no semi
type tt = string;
});
module type SigResult = {let result: int;};
module type SigResult = {
let result: int;
};
module type ASig = {let a: int;};
module type BSig = {let b: int;};
module type ASig = {
let a: int;
};
module type BSig = {
let b: int;
};
module AMod = {
let a = 10;
};
Expand Down Expand Up @@ -422,7 +432,9 @@ Format modules no semi
};

/* From http://stackoverflow.com/questions/1986374/higher-order-type-constructors-and-functors-in-ocaml */
module type Type = {type t;};
module type Type = {
type t;
};
module Char = {
type t = char;
};
Expand Down Expand Up @@ -483,7 +495,9 @@ Format modules no semi
let myValue = {recordField: "hello"};
});

module type HasInt = {let x: int;};
module type HasInt = {
let x: int;
};

module MyModule = {
let x = 10;
Expand Down
12 changes: 9 additions & 3 deletions test/whitespace-rei.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,22 @@ Format whitespace in .rei files
include Shared;

/** doc attached */
module type X = {let x: int;};
module type X = {
let x: int;
};

/** doc attached with whitespace */

module type X = {let x: int;};
module type X = {
let x: int;
};

/** doc attached with whitespace and comment */

/* test */
module type X = {let x: int;};
module type X = {
let x: int;
};

/** doc attached */
module X: MX;
Expand Down
8 changes: 6 additions & 2 deletions test/wrapping-re.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -2568,8 +2568,12 @@ Format wrapping in .re files
1 + 2 + 3 + 3,
);

module type ASig = {let a: int;};
module type BSig = {let b: int;};
module type ASig = {
let a: int;
};
module type BSig = {
let b: int;
};
module AMod = {
let a = 10;
};
Expand Down

0 comments on commit 229ffdf

Please sign in to comment.