reasonml / reason

Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems
http://reasonml.github.io
MIT License
10.08k stars 425 forks source link

Better printing extensions/attributes inside sequences (and other nested expressions) #2677

Open davesnx opened 1 year ago

davesnx commented 1 year ago

Extensions are still a work in progress, there’s a TODO in the code and might appear some edge-cases after this PR #2674.

There’s a bit of ambiguity on extensions/comments/sequences and I lack the vision to have a clear desired output, so let me explain what are the differences with code examples.

Current pp output:

/* Extension with pexp_apply */

[%defer
  cleanup();
]

/* Extension with comment with pexp_apply */

[%defer
  /* 2. comment attached to expr in extension */
  cleanup();
];

/* Let sequence + extension with pexp_apply */

let () = {
  /* random let binding */
  let x = 1;
  /* 1. comment attached to extension */
  [%defer cleanup()];
  /* 3. comment attached to next expr */
  something_else();
};

/* Let sequence + extension with comment with pexp_apply */

let () = {
  /* random let binding */
  let x = 1;
  /* 1. comment attached to extension */
  [%defer
   /* 2. comment attached to expr in extension */
   cleanup()];
  /* 3. comment attached to next expr */
  something_else();
};

Note how being inside a sequence makes formatting different and I think this shoudn’t be the case, but unsure if applying the same formatting would make sense. That’s why I’m openning this issue.

Related: Attributes and other expressions add single space as identation.