Skip to content

Commit 4565f26

Browse files
committed
Handle variant printing with comment
1 parent d77c9a5 commit 4565f26

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

compiler/syntax/src/res_printer.ml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,38 @@ and print_constructor_declarations ~state ~private_flag
15491549

15501550
and print_constructor_declaration2 ~state i
15511551
(cd : Parsetree.constructor_declaration) cmt_tbl =
1552-
let attrs = print_attributes ~state cd.pcd_attributes cmt_tbl in
1552+
let comment_attrs, attrs =
1553+
List.partition
1554+
(fun ((id, payload) : Parsetree.attribute) ->
1555+
match (id, payload) with
1556+
| ( {txt = "res.doc"},
1557+
PStr
1558+
[
1559+
{
1560+
pstr_desc =
1561+
Pstr_eval
1562+
({pexp_desc = Pexp_constant (Pconst_string (_, _))}, _);
1563+
};
1564+
] ) ->
1565+
true
1566+
| _ -> false)
1567+
cd.pcd_attributes
1568+
in
1569+
let comment_doc =
1570+
match comment_attrs with
1571+
| [] -> Doc.nil
1572+
| comment_attrs ->
1573+
Doc.concat
1574+
[
1575+
Doc.group
1576+
(Doc.join_with_sep
1577+
(List.map
1578+
(fun attr -> print_attribute ~state attr cmt_tbl)
1579+
comment_attrs));
1580+
Doc.hard_line;
1581+
]
1582+
in
1583+
let attrs = print_attributes ~state attrs cmt_tbl in
15531584
let is_dot_dot_dot = cd.pcd_name.txt = "..." in
15541585
let bar =
15551586
if i > 0 || cd.pcd_attributes <> [] || is_dot_dot_dot then Doc.text "| "
@@ -1571,6 +1602,7 @@ and print_constructor_declaration2 ~state i
15711602
in
15721603
Doc.concat
15731604
[
1605+
comment_doc;
15741606
bar;
15751607
Doc.group
15761608
(Doc.concat

0 commit comments

Comments
 (0)