Refactor/attach comments on node#278
Conversation
|
There is still an issue with handling some trailing comments. This behavior is also found in master Input: class T {
void t() {
if (e) {
// empty
} // comment
else {
}
}
}Output: class T {
void t() {
if (e) {
// empty
} else {} // comment
}
} |
WIP parser: refactor prettier ignore support
eaa7293 to
108f5b3
Compare
00b96d2 to
9a623e6
Compare
376dcd0 to
81753d4
Compare
|
It is ready for review. As I modified the behavior in the parser, I requested a review from you @bd82. Please let mme know if you have time to review or not 😄 I think there will be some edge cases that are not correctly handled, like those I corrected in labeledStatements and ifStatements. I think it could be good to fix these cases in separate PRs, as it will be difficult to review otherwise. |
|
Hi @clement26695 I do not actually remember what was the previous behavior of comments handling and I do not have the time to go in depth in this large PR. Can you describe what was done? what was the change and why? |
|
Basically, I attached the comments on nodes when possible, instead of tokens. Indeed, it is much easier to process it then in the printer, due to the way the group command work in prettier. So, if you have time to look at how we attach the comments on nodes, it would be great, but otherwise, @Shaolans could have a look, and we could try to optimise it (if necessary) in other PRs |
|
Attaching the comments on nodes instead of Tokens seems to make sense.
|
|
You're right, it is quite unclear. Will try to clarify/document the process |
248f888 to
4e8fe2b
Compare
|
Done ! I hope it is more understandable |
Yes makes much more sense now. I think you could have also added info to the CSTNodes during parsing:
Instead of creating some of these helper data structures and than perform the logic |
| return concat([this.visit(compilationUnit[0]), ctx.EOF[0]]); | ||
|
|
||
| // Do not add additional line if only comments in file | ||
| const additionalLine = isNaN(compilationUnit[0].location.startOffset) |
There was a problem hiding this comment.
For me, it is just good practice to end a file by an empty line. But I don't know exactly why 😅
There was a problem hiding this comment.
IMO, we should not enforce it since it JHipster app do not have that additional line or at least discuss about it.
Anyway great work !
Fix #262 and fix #276.
Will help to fix issue #270