Skip to content

Fix comments formatted away in function with no args #7095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- Fix parsing issue with nested variant pattern type spreads. https://github.com/rescript-lang/rescript-compiler/pull/7080
- Fix JSX settings inheritance: only 'version' propagates to dependencies, preserving their 'mode' and 'module'. https://github.com/rescript-lang/rescript-compiler/pull/7094
- Fix variant cast to int. https://github.com/rescript-lang/rescript-compiler/pull/7058
- Fix comments formatted away in function without arguments. https://github.com/rescript-lang/rescript-compiler/pull/7095

#### :nail_care: Polish

Expand Down
19 changes: 16 additions & 3 deletions compiler/syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4842,9 +4842,22 @@ and print_arguments_with_callback_in_last_position ~state args cmt_tbl =
and print_arguments ~state ?(partial = false)
(args : (Asttypes.arg_label * Parsetree.expression) list) cmt_tbl =
match args with
| [(Nolabel, {pexp_desc = Pexp_construct ({txt = Longident.Lident "()"}, _)})]
->
Doc.text "()"
| [
( Nolabel,
{
pexp_desc = Pexp_construct ({txt = Longident.Lident "()"}, _);
pexp_loc = loc;
} );
] ->
if has_leading_line_comment cmt_tbl loc then
let cmt = print_comments Doc.nil cmt_tbl loc in
Doc.concat
[
Doc.lparen;
Doc.indent (Doc.group (Doc.concat [Doc.soft_line; cmt]));
Doc.rparen;
]
else Doc.text "()"
| [(Nolabel, arg)] when ParsetreeViewer.is_huggable_expression arg ->
let arg_doc =
let doc = print_expression_with_comments ~state arg cmt_tbl in
Expand Down
26 changes: 26 additions & 0 deletions tests/syntax_tests/printer/comments/expected/expr.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,32 @@ let multiply = (
/* c2 */ m2 /* c3 */,
) => ()

f(
// a
// b
// c
)

f(
// a
// b
// c
)

let x = {
f(
// a
// b
// c
)

f(
// a
// b
// c
)
}

f(() => 1)
// c1
f(_ => 1)
Expand Down
29 changes: 29 additions & 0 deletions tests/syntax_tests/printer/comments/expr.res
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,35 @@ let f = (/* c0 */ ~greeting /* c1 */, /* c2 */ ~from /* c3 */ as /* c4 */ hometo
let multiply = (/* c-2 */ type t /* c-1 */,/* c0 */ m1 /* c1 */, /* c2 */ m2 /* c3 */) => ()
let multiply = (/* c-4 */ type t /* c-3 */,/* c0 */ m1 /* c1 */, /* c-2 */ type s /* c-1 */, /* c2 */ m2 /* c3 */) => ()

f(
// a
// b
// c
)

f(
// a
// b
// c
()
)

let x = {
f(
// a
// b
// c
)


f(
// a
// b
// c
()
)
}

f(()
// c1
=> 1);
Expand Down