New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add info re: comment handling to the Plugin API documentation #4290
Comments
@suchipi The documentation is much needed to make plugin development for new developer easier. Hope it can be added soon. (I'm one who doesn't know but need to know what |
If someone can explain some of these functions to me, I can take a stab at writing documentation. I'm currently trying to figure it out myself... |
@siefkenj Unfortunately, that's a lot to investigate and explain. I might be able to help you if you ask more specific bite-sized questions. |
Okay, here's what I understand so far:
Also, I don't understand the purpose of It seems the general strategy for printing comments is to find which AST node the comment is contained in, call Other Questions
|
Attaching comments and printing them are separate processes. I've mostly dealt with the former, so I'm going to answer only about that now.
If a comment isn't "own-line" and isn't "end-of-line" either, then it's categorized as "remaining". Each category of the three has its own rules for attaching to AST nodes. The rules can be extended by callbacks optionally provided by the printer ( A printer can provide other callbacks to the comment-attaching logic:
|
Should |
They totally should. |
Why does the current plugin documentation say |
Yes, it's not about |
The work in PR #8407 was already a great help to enable the integration of comments. Thanks a lot for these additions! Currently I get the error Are the |
The documentation doesn't really make it clear which methods one should implement to make use of the automatic comment handling. Reading the docs, I got the impression that I don't have to implement any and it will all work automatically. After lots of trial and error and reading of Prettier source code I've finally figured out that one needs to implement at least two methods:
The documentation also only gives you a vague info as to what sort of data the
What I have figured out about these comment nodes:
|
We should document that you can add
handleComments
,getCommentChildNodes
,canAttachComment
, andprintComment
to your printer, what they're for, how prettier will use them, and how to useaddLeadingComment
,addTrailingComment
, andaddDanglingComment
. As part of this, we should explain what it means for a comment to be "leading", "trailing", "dangling", "ownLine", "endOfLine", and "remaining".cc @mgrip
The text was updated successfully, but these errors were encountered: