Skip to content

Commit

Permalink
fix(grainfmt): Stop adding an extra line after block comments (grain-…
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusroberts authored Sep 15, 2022
1 parent cc9b8b5 commit 4e4903f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion compiler/src/formatting/comment_utils.re
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ let rec new_comments_inner =

| 1 => [
switch (prev_cmt) {
| Line(_) => Doc.nil
| Line(_)
| Doc(_) => Doc.nil
| _ => Doc.hardLine
},
comment_to_doc(cmt),
Expand Down
12 changes: 2 additions & 10 deletions compiler/src/formatting/format.re
Original file line number Diff line number Diff line change
Expand Up @@ -4187,14 +4187,6 @@ let format_ast =
toplevel_print(~original_source, ~comments, stmt);
};

let leading_comments = [];

let cleaned_comments =
remove_used_comments(
~remove_comments=leading_comments,
parsed_program.comments,
);

let get_attributes = (stmt: Parsetree.toplevel_stmt) => {
let attributes = stmt.ptop_attributes;
print_attributes(attributes);
Expand All @@ -4204,14 +4196,14 @@ let format_ast =

let final_doc =
switch (parsed_program.statements) {
| [] => Comment_utils.new_comments_to_docs(cleaned_comments)
| [] => Comment_utils.new_comments_to_docs(parsed_program.comments)
| _ =>
let top_level_stmts =
block_item_iterator(
~previous=TopOfFile,
~get_loc,
~print_item,
~comments=cleaned_comments,
~comments=parsed_program.comments,
~print_attribute=get_attributes,
~original_source,
parsed_program.statements,
Expand Down
4 changes: 4 additions & 0 deletions compiler/test/formatter_inputs/comments.gr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

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

/**
* Then a doc
*/
// Then a line
let myfun1 = (/* a */ x , y) => 10

let myfun2 = (x /*post*/, y) => 10
Expand Down
4 changes: 4 additions & 0 deletions compiler/test/formatter_outputs/comments.gr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

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

/**
* Then a doc
*/
// Then a line
let myfun1 = (/* a */ x, y) => 10

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

0 comments on commit 4e4903f

Please sign in to comment.