Skip to content

Commit

Permalink
fix(compiler): fix formatter multiple data bug (#1282)
Browse files Browse the repository at this point in the history
* Fixed an issue with multiple data declarations and comments

* Formatted formatter

Co-authored-by: Marcus Roberts <[email protected]>
  • Loading branch information
marcusroberts and Marcus Roberts committed May 29, 2022
1 parent 1590a37 commit f6fd962
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
11 changes: 9 additions & 2 deletions compiler/grainformat/format.re
Original file line number Diff line number Diff line change
Expand Up @@ -3723,13 +3723,20 @@ let data_print =
Doc.concat([Doc.comma, Doc.hardLine]),
List.map(
data => {
let (expt, decl) = data;
let (expt, decl: Parsetree.data_declaration) = data;

let data_comments =
Comment_utils.get_comments_inside_location(
~location=decl.pdata_loc,
comments,
);

Doc.concat([
switch ((expt: Asttypes.export_flag)) {
| Nonexported => Doc.nil
| Exported => Doc.text("export ")
},
print_data(~original_source, ~comments, decl),
print_data(~original_source, ~comments=data_comments, decl),
]);
},
datas,
Expand Down
12 changes: 12 additions & 0 deletions compiler/test/formatter_inputs/enum_long.gr
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@ export enum Test {
Test( Shape<
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 > ),
}

enum EvenNumber {
Zero, // comment 0
OddPlusOne(OddNumber), // comment 1
// comment 2
// comment 3
},
enum OddNumber {
// comment 4
// comment 5
EvenPlusOne(EvenNumber),
} // comment 6
12 changes: 12 additions & 0 deletions compiler/test/formatter_outputs/enum_long.gr
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,15 @@ export enum Test {
>
),
}

enum EvenNumber {
Zero, // comment 0
OddPlusOne(OddNumber), // comment 1
// comment 2
// comment 3
},
enum OddNumber {
// comment 4
// comment 5
EvenPlusOne(EvenNumber),
} // comment 6

0 comments on commit f6fd962

Please sign in to comment.