Skip to content

Commit f6fd962

Browse files
marcusrobertsMarcus Roberts
andauthored
fix(compiler): fix formatter multiple data bug (#1282)
* Fixed an issue with multiple data declarations and comments * Formatted formatter Co-authored-by: Marcus Roberts <marcus@marcusr.com>
1 parent 1590a37 commit f6fd962

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

compiler/grainformat/format.re

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3723,13 +3723,20 @@ let data_print =
37233723
Doc.concat([Doc.comma, Doc.hardLine]),
37243724
List.map(
37253725
data => {
3726-
let (expt, decl) = data;
3726+
let (expt, decl: Parsetree.data_declaration) = data;
3727+
3728+
let data_comments =
3729+
Comment_utils.get_comments_inside_location(
3730+
~location=decl.pdata_loc,
3731+
comments,
3732+
);
3733+
37273734
Doc.concat([
37283735
switch ((expt: Asttypes.export_flag)) {
37293736
| Nonexported => Doc.nil
37303737
| Exported => Doc.text("export ")
37313738
},
3732-
print_data(~original_source, ~comments, decl),
3739+
print_data(~original_source, ~comments=data_comments, decl),
37333740
]);
37343741
},
37353742
datas,

compiler/test/formatter_inputs/enum_long.gr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,15 @@ export enum Test {
66
Test( Shape<
77
String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String > ),
88
}
9+
10+
enum EvenNumber {
11+
Zero, // comment 0
12+
OddPlusOne(OddNumber), // comment 1
13+
// comment 2
14+
// comment 3
15+
},
16+
enum OddNumber {
17+
// comment 4
18+
// comment 5
19+
EvenPlusOne(EvenNumber),
20+
} // comment 6

compiler/test/formatter_outputs/enum_long.gr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,15 @@ export enum Test {
9494
>
9595
),
9696
}
97+
98+
enum EvenNumber {
99+
Zero, // comment 0
100+
OddPlusOne(OddNumber), // comment 1
101+
// comment 2
102+
// comment 3
103+
},
104+
enum OddNumber {
105+
// comment 4
106+
// comment 5
107+
EvenPlusOne(EvenNumber),
108+
} // comment 6

0 commit comments

Comments
 (0)