From 229ffdffa9a44983159b941fb59c158536b2a542 Mon Sep 17 00:00:00 2001 From: Sander Date: Tue, 18 Apr 2023 00:31:53 +0200 Subject: [PATCH] Improve printing of modules types with one line inside (#2709) * improve printing of modules with one line * add history entry --- HISTORY.md | 1 + src/reason-parser/reason_pprint_ast.ml | 2 +- test/modules.t/run.t | 28 +++++++++++++++++++------- test/modules_no_semi.t/run.t | 28 +++++++++++++++++++------- test/whitespace-rei.t/run.t | 12 ++++++++--- test/wrapping-re.t/run.t | 8 ++++++-- 6 files changed, 59 insertions(+), 20 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index b2ce46405..4e1bff80f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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 diff --git a/src/reason-parser/reason_pprint_ast.ml b/src/reason-parser/reason_pprint_ast.ml index 18b03f196..b0880d702 100644 --- a/src/reason-parser/reason_pprint_ast.ml +++ b/src/reason-parser/reason_pprint_ast.ml @@ -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 diff --git a/test/modules.t/run.t b/test/modules.t/run.t index b28898cd2..27c94f76d 100644 --- a/test/modules.t/run.t +++ b/test/modules.t/run.t @@ -113,7 +113,9 @@ Format modules tmp + 30; }; - module type HasTT = {type tt;}; + module type HasTT = { + type tt; + }; module SubModule: HasTT = { type tt = int; @@ -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); @@ -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; }; @@ -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; }; @@ -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; diff --git a/test/modules_no_semi.t/run.t b/test/modules_no_semi.t/run.t index 388d7f2ef..6f5887008 100644 --- a/test/modules_no_semi.t/run.t +++ b/test/modules_no_semi.t/run.t @@ -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; @@ -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); @@ -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; }; @@ -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; }; @@ -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; diff --git a/test/whitespace-rei.t/run.t b/test/whitespace-rei.t/run.t index f35d5f832..e4b4b700d 100644 --- a/test/whitespace-rei.t/run.t +++ b/test/whitespace-rei.t/run.t @@ -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; diff --git a/test/wrapping-re.t/run.t b/test/wrapping-re.t/run.t index e0dff470e..c8823ac54 100644 --- a/test/wrapping-re.t/run.t +++ b/test/wrapping-re.t/run.t @@ -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; };