nixfmt icon indicating copy to clipboard operation
nixfmt copied to clipboard

Move comments to the syntax following them

Open Lucus16 opened this issue 6 years ago • 0 comments

Currently, all comments are parsed after tokens, but comments generally apply to the token that follows it, with the exception of trailing comments on the same line. Many formatting cases based on reordering expressions can't be done properly until comments are attached to the tokens they apply to. I tried parsing comments before the tokens, but this cannot be done efficiently and elegantly.

The best way forward is to make a pass over the entire syntax tree and moving comments from after their intial token to before the next token. This pass can simultaneously move some comments into better positions where they don't interrupt formatting flow.

Lucus16 avatar Jul 29 '19 11:07 Lucus16