-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
We are facing lots of small issues regarding comment insertion. At the time of #2311 we were still exploring the issue and after maintaining this way of handling comments for couple of months, I think it seems like a better way of handling should be discussed. I am not linking all comment related hot-fix PRs but we had couple of them 😄
Proposal
Let's parse comments and produce a CommentedParseTree just like we are lexing comments (we have CommentedTokenStream vs TokenStream etc). This way re-constructing the comments section would not need:
- Search the unformatted code
- Search the formatted code
We would be simply formatting comments just like we are formatting other stuff like Tys, exprs etc. I believe this would be a little bit faster and most importantly it could lead to less problems. Currently once we have some edge case stuff happening related to the comments we tend to introduce rather "hacky" solutions as the interaction between formatter and comment handler is not simple enough.
With parsed comments, if we can also collect some sort of context we could still be sure that we are not altering the intentional comment styles (rust classifies comments like this)
Any thoughts on this? cc @FuelLabs/tooling