rescript-lang / rescript-compiler

The compiler for ReScript.
https://rescript-lang.org
Other
6.75k stars 449 forks source link

Formatting: Comment removes `ppx`-annotation and moves comment above `ppx`-annotation #6069

Closed lessp closed 1 month ago

lessp commented 1 year ago

Stumbled upon a couple of cases while trying to figure out how to get doc-strings to work.

First example

The formatter will turn this:

@genType
/*** Hello, World */
let make = () => ()

Into this:

/*** Hello, World */
let make = () => ()

Second example

The formatter will turn:

module Foo: {
  @genType
  /* Hello, World */
  let make: unit => unit
} = {
  let make = () => () 
}

Into this:

module Foo: {
  @genType
  let /* Hello, World */
  make: unit => unit
} = {
  let make = () => ()
}

Third example (might be the desired result)

The formatter will turn:

@genType
/// Hello, World
let make = () => ()

Into this:

/// Hello, World
@genType
let make = () => ()

Reproduce

Click format in the following example:

https://rescript-lang.org/try?version=v10.1.2&code=AIcwpgdgKgngDmAUAegFToAQAkwBtcD2ANBgOoEBOuAJhqsormAC4YC2AhgNZgYC8GABQBKfgD4hwxIjYFqAVyYYAYgQIAuDAG9EGDKEiwEujGmx5CJclVr0TTVpx6b5EAJas+E1x8QBffm17FnZuXgERcUkMf2kDaHgkZGTzfGIyShpGEKdw6K9JRCA

cristianoc commented 1 year ago

/// comment behind the scene is a standalone annotation. This is the same as:

@genType

@@someStandaloneAnnotation

let make = () => ()

so @genType is not attached to make. One could give an error in such a situation. But there's no good code it could reformat to.

cristianoc commented 1 year ago

(because there's nothing to attach @genType to in the parse tree)

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.