-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support request: how do I get a DocBlock when there are no nodes #36
Comments
The issue here is that There are several ways this could be solved:
All variants seem somewhat ugly, so I'm not really sure what to do about this :/ |
I agree with you that the above solutions are less than optimal. Let's see if another solution is possible. As such, is the following use case correct behaviour? Code <?php
// this is a test
/**
* Short description
*/
/* this is a common multiline comment */
$a * $b == 1 + 2; According to a var_dump of the nodes will 'Expr_Equal' node, the 'Expr_Mul' node and the 'Expr_Variable' $a ALL have the comment 'this is a test', 'Short description' and 'this is a common multiline' comment. I would have expected that 'this is a test' and 'this is a common multiline comment' would have belonged to the file (shouldn't the file actually be a top parent node?) and that the Short description would only have belonged to the Expr_Equal node. Example clarifying my last statement: <?php
/** @var \SimpleXMLElement $a */
$a * $b == 1 + 2; The above indicates that the Expr_Equal contains a variable $a which is of type SimpleXMLElement in this specific context. It may be assumed that $a is the same type in subsequent contexts but only here we know for sure. |
Hey @nikic, I'd love to hear your thoughts on the above if you have time, Thanks in advance. |
Hey @mvriel. I must have missed the notification for your comment, sorry :/ Regarding the comments, no, this is not the intended behavior and I didn't notice that this happens until now. Though thinking about it again, it's quite logical that it happens: Just like all (also nested) nodes get assigned a line number, nested nodes also get assigned the comments. Fixing this will be rather hard though, as it can't really be done in a generic way, at least I don't see one. Rather I'd have to assign comments only to statements (and expressions in statement use). But it's probably still worth to do it for the memory savings. |
maybe a node / container / something with "lostandfound"-comments ? :) aka "not assignable" - comments? |
Ran into this today too. All docblocks/comments get accumulated to the next node found or dropped if none. This makes it really inconvenient to use the same visitor/parser concept for a mixed tree where some files have docblocks without comments, etc. I wish there was a mode where docblock/comments where just emmited as individual nodes like anything else, without being required to be attached somewhere. |
Adding this as an option to avoid breaking people's tests. Some of the test results show pretty clearly that we are incorrectly assigning the same comment multiple times for nested nodes (mentioned in #36).
Thanks @nikic! I had missed the addition of the NOP statement so that should enable me to introduce file-level docblocks. Thanks! |
@mvriel You didn't miss anything, I've only added them yesterday ;) The date info on that commit is off, because I rebased it off an older branch. |
Hey @nikic,
I received the following bug report in phpDocumentor/phpDocumentor2: phpDocumentor/phpDocumentor#604
The reporter indicates that the first DocBlock could not be found when there are no nodes. This is verified behaviour since I try to claim the file-level DocBlock in a NodeVisitor using the beforeTraverse method.
Can you provide me with a clue what the best way would be to still obtain the first DocComment in a file using PHP-Parser? (if PHP-Parser supports that)
The text was updated successfully, but these errors were encountered: