Skip to content

Commit 4e4903f

Browse files
fix(grainfmt): Stop adding an extra line after block comments (#1436)
1 parent cc9b8b5 commit 4e4903f

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

compiler/src/formatting/comment_utils.re

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,8 @@ let rec new_comments_inner =
521521

522522
| 1 => [
523523
switch (prev_cmt) {
524-
| Line(_) => Doc.nil
524+
| Line(_)
525+
| Doc(_) => Doc.nil
525526
| _ => Doc.hardLine
526527
},
527528
comment_to_doc(cmt),

compiler/src/formatting/format.re

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4187,14 +4187,6 @@ let format_ast =
41874187
toplevel_print(~original_source, ~comments, stmt);
41884188
};
41894189

4190-
let leading_comments = [];
4191-
4192-
let cleaned_comments =
4193-
remove_used_comments(
4194-
~remove_comments=leading_comments,
4195-
parsed_program.comments,
4196-
);
4197-
41984190
let get_attributes = (stmt: Parsetree.toplevel_stmt) => {
41994191
let attributes = stmt.ptop_attributes;
42004192
print_attributes(attributes);
@@ -4204,14 +4196,14 @@ let format_ast =
42044196

42054197
let final_doc =
42064198
switch (parsed_program.statements) {
4207-
| [] => Comment_utils.new_comments_to_docs(cleaned_comments)
4199+
| [] => Comment_utils.new_comments_to_docs(parsed_program.comments)
42084200
| _ =>
42094201
let top_level_stmts =
42104202
block_item_iterator(
42114203
~previous=TopOfFile,
42124204
~get_loc,
42134205
~print_item,
4214-
~comments=cleaned_comments,
4206+
~comments=parsed_program.comments,
42154207
~print_attribute=get_attributes,
42164208
~original_source,
42174209
parsed_program.statements,

compiler/test/formatter_inputs/comments.gr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
let myfun = (/* a */ x /*post*/, y) => 10
77

8+
/**
9+
* Then a doc
10+
*/
11+
// Then a line
812
let myfun1 = (/* a */ x , y) => 10
913

1014
let myfun2 = (x /*post*/, y) => 10

compiler/test/formatter_outputs/comments.gr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
let myfun = (/* a */ x, /*post*/ y) => 10
77

8+
/**
9+
* Then a doc
10+
*/
11+
// Then a line
812
let myfun1 = (/* a */ x, y) => 10
913

1014
let myfun2 = (x, /*post*/ y) => 10

0 commit comments

Comments
 (0)