From fd4611acfd3372a4270c2a8deabbbe0a6dec1947 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Sun, 28 Jul 2024 19:47:10 -0700 Subject: [PATCH] always break at `*/` of nonempty doc comments (#2780) * always break at `*/` of nonempty doc comments * fix test * fix 4.10 test * fix 4.12 test --- src/reason-parser/reason_pprint_ast.ml | 9 ++++++++- test/4.10/attributes-re.t/run.t | 10 ++++++---- test/4.12/attributes-re.t/run.t | 10 ++++++---- test/infix.t/run.t | 9 ++++++--- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/reason-parser/reason_pprint_ast.ml b/src/reason-parser/reason_pprint_ast.ml index 7e0f18bbd..14639c306 100644 --- a/src/reason-parser/reason_pprint_ast.ml +++ b/src/reason-parser/reason_pprint_ast.ml @@ -6660,8 +6660,15 @@ let printer = object(self:'self) PStr [{ pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string(text, _, None)) } , _); pstr_loc }] ; _ } -> + let break = if text = "" then Layout.IfNeed else Always_rec in let text = if text = "" then "/**/" else "/**" ^ text ^ "*/" in - makeList ~inline:(true, true) ~postSpace:true ~preSpace:true ~indent:0 ~break:IfNeed [atom ~loc:pstr_loc text] + makeList + ~inline:(true, true) + ~postSpace:true + ~preSpace:true + ~indent:0 + ~break + [atom ~loc:pstr_loc text] | { attr_name; attr_payload; _ } -> self#payload "@" attr_name attr_payload (* [@@ ... ] Attributes that occur after a major item in a structure/class *) diff --git a/test/4.10/attributes-re.t/run.t b/test/4.10/attributes-re.t/run.t index 379f80c91..5810e6ddc 100644 --- a/test/4.10/attributes-re.t/run.t +++ b/test/4.10/attributes-re.t/run.t @@ -25,7 +25,8 @@ Print the formatted file /**removed text on type def*/ [@itemAttributeOnTypeDef] type itemText = int; - type nodeText = /**removed text on item*/ int; + type nodeText = + /**removed text on item*/ int; /**removed text on type def*/ [@itemAttributeOnTypeDef] type nodeAndItemText = @@ -35,7 +36,8 @@ Print the formatted file [@itemAttributeOnTypeDef] type itemDoc = int; [@itemAttributeOnTypeDef] - type nodeDoc = /**removed text on item*/ int; + type nodeDoc = + /**removed text on item*/ int; /**removed doc on type def*/ [@itemAttributeOnTypeDef] type nodeAndItemDoc = @@ -831,8 +833,8 @@ Print the formatted file Type-check basics $ ocamlc -c -pp 'refmt --print binary' -intf-suffix .rei -impl formatted.re - File "formatted.re", line 503, characters 4-10: - 503 | concat; + File "formatted.re", line 505, characters 4-10: + 505 | concat; ^^^^^^ Warning 10: this expression should have type unit. diff --git a/test/4.12/attributes-re.t/run.t b/test/4.12/attributes-re.t/run.t index ac4687d77..dcc6bf875 100644 --- a/test/4.12/attributes-re.t/run.t +++ b/test/4.12/attributes-re.t/run.t @@ -25,7 +25,8 @@ Print the formatted file /**removed text on type def*/ [@itemAttributeOnTypeDef] type itemText = int; - type nodeText = /**removed text on item*/ int; + type nodeText = + /**removed text on item*/ int; /**removed text on type def*/ [@itemAttributeOnTypeDef] type nodeAndItemText = @@ -35,7 +36,8 @@ Print the formatted file [@itemAttributeOnTypeDef] type itemDoc = int; [@itemAttributeOnTypeDef] - type nodeDoc = /**removed text on item*/ int; + type nodeDoc = + /**removed text on item*/ int; /**removed doc on type def*/ [@itemAttributeOnTypeDef] type nodeAndItemDoc = @@ -831,8 +833,8 @@ Print the formatted file Type-check basics $ ocamlc -c -pp 'refmt --print binary' -intf-suffix .rei -impl formatted.re - File "formatted.re", line 503, characters 4-10: - 503 | concat; + File "formatted.re", line 505, characters 4-10: + 505 | concat; ^^^^^^ Warning 10 [non-unit-statement]: this expression should have type unit. diff --git a/test/infix.t/run.t b/test/infix.t/run.t index 9725da45e..ec6322295 100644 --- a/test/infix.t/run.t +++ b/test/infix.t/run.t @@ -591,7 +591,8 @@ Format infix operators /** * Try with || - */ x.contents + */ + x.contents || something + 1 ? hello : goodbye; @@ -619,7 +620,8 @@ Format infix operators /** * Try with && - */ x.contents + */ + x.contents && something + 1 ? hello : goodbye; @@ -739,7 +741,8 @@ Format infix operators something ? str.[0] = somethingElse : goodbye; - /** And this */ y := + /** And this */ + y := something ? y := somethingElse : goodbye; arr[0] := something