Attach documentation comments to nodes - #4871
Conversation
|
Will it works for Also, I forgot to close #4768, but it was already resolved with our Since my initial issue is closed, do we really need this new feature here? It would requires UX to change again, and the Symfony PHPStorm plugin should be modified as well. |
|
📋 PR Summary This incremental change refines the documentation-comment feature: Changes
|
This is generic, so it should work just fine. |
|
Cool, thanks! When merged/released, I will work on UX & Symfony PHPStorm plugin to re-align things with this PR. |
fcbb983 to
12bb3aa
Compare
There was a problem hiding this comment.
📋 Upsun Dispatch Review: incremental · 18 files reviewed · no new issues · 2 still open
Outstanding from earlier reviews:
- #3650339795 — src/Node/TypesNode.php:32: Two divergent construction sites for the same nodes invite line-number drift and maintenance errors.
- #3650339797 — src/Node/Node.php:145: Ambiguous @internal marking on a method the feature relies on causes API-stability confusion.
12bb3aa to
d864497
Compare
There was a problem hiding this comment.
📋 Upsun Dispatch Review: full · 17 files reviewed · 🔵 1 info · 2 still open
Outstanding from earlier reviews:
- #3650339795 — src/Node/TypesNode.php:32: Two divergent construction sites for the same nodes invite line-number drift and maintenance errors.
- #3650339797 — src/Node/Node.php:145: Ambiguous @internal marking on a method the feature relies on causes API-stability confusion.
|
Opened Haehnchen/idea-php-symfony2-plugin#2836, UX PR will follows when this one get merged/released. |
d864497 to
4636611
Compare
There was a problem hiding this comment.
📋 Upsun Dispatch Review: incremental · 26 files reviewed · 🔵 2 infos · 1 still open
Outstanding from earlier reviews:
- #3652057652 — src/TokenParser/TypesTokenParser.php:40: Redundant construction and duplicated type state make the model wasteful and easy to desynchronize.
| final class NodeDocumentation | ||
| { | ||
| /** @var \WeakMap<Node, string>|null */ | ||
| private static ?\WeakMap $pending = null; |
There was a problem hiding this comment.
🔵 Info — Global mutable static state is harder to test and reason about than the instance state it replaced.
$pending and $targets are process-global static \WeakMaps, replacing the former per-Parser instance state (pendingDocumentation/documentationTargets) that was reset at the start and end of each parse(). The state is now shared across all Parser instances and never reset; entries only clear when the keyed Node is garbage-collected. This is safe for single-threaded parsing (nodes are distinct objects per parse and WeakMap keys are weak), but it makes the stage→promote / set→setTarget lifecycle harder to test and reason about than the scoped instance state it replaced.
37205b4 to
099455d
Compare
There was a problem hiding this comment.
📋 Upsun Dispatch Review: incremental · 26 files reviewed · no new issues · 3 still open
Outstanding from earlier reviews:
- #3652057652 — src/TokenParser/TypesTokenParser.php:40: Redundant construction and duplicated type state make the model wasteful and easy to desynchronize.
- #3653256238 — src/ExpressionParser.php:314: Duplicated conversion logic across parsers is easy to desynchronize as documentation handling evolves.
- #3653256239 — src/Node/NodeDocumentation.php:22: Global mutable static state is harder to test and reason about than the instance state it replaced.
099455d to
fc2ffbe
Compare
There was a problem hiding this comment.
📋 Upsun Dispatch Review: full · 67 files reviewed · 🔵 3 infos · 2 still open
🔵 Info (P2 — suggestions) — outside diff range
src/ExpressionParser.php· design
parseExpression()unconditionally callsNodeDocumentation::set($expr, $documentationToken)on every expression it parses, so the leading token's documentation is attached to arbitrary expression nodes and correctness depends entirely onDocumentationNodeVisitor::leaveNode()later stripping it from everyAbstractExpressionthat is not anAssignContextVariable/LocalVariable. If that visitor is unregistered or reordered, or a new documented-target expression type is introduced, documentation silently leaks onto (or is wrongly removed from) nodes.
Review details
Commit: Commit fc2ffbe
Model: claude-opus-4-8
Panel: security · correctness · robustness · design
Outstanding from earlier reviews:
- #3652057652 — src/TokenParser/TypesTokenParser.php:40: Redundant construction and duplicated type state make the model wasteful and easy to desynchronize.
- #3653256238 — src/ExpressionParser.php:314: Duplicated conversion logic across parsers is easy to desynchronize as documentation handling evolves.
There was a problem hiding this comment.
📋 Upsun Dispatch Review: incremental · 59 files reviewed · no new issues · 3 still open
Outstanding from earlier reviews:
- #3652057652 — src/TokenParser/TypesTokenParser.php:40: Redundant construction and duplicated type state make the model wasteful and easy to desynchronize.
- #3659503446 — src/NodeVisitor/DocumentationNodeVisitor.php:35: Undocumented root-node assumption makes the visitor unsafe to reuse on subtrees.
- #3659503454 — src/NodeVisitor/DocumentationNodeVisitor.php:53: Stale AST references accumulate across compilations when traversal throws.
57acc0a to
d63f38e
Compare
There was a problem hiding this comment.
📋 Upsun Dispatch Review: full · 19 files reviewed · 🔵 1 info · 4 still open
Outstanding from earlier reviews:
- #3652057652 — src/TokenParser/TypesTokenParser.php:40: Redundant construction and duplicated type state make the model wasteful and easy to desynchronize.
- #3653256238 — src/ExpressionParser.php:314: Duplicated conversion logic across parsers is easy to desynchronize as documentation handling evolves.
- #3659503446 — src/NodeVisitor/DocumentationNodeVisitor.php:35: Undocumented root-node assumption makes the visitor unsafe to reuse on subtrees.
- #3659503454 — src/NodeVisitor/DocumentationNodeVisitor.php:53: Stale AST references accumulate across compilations when traversal throws.
There was a problem hiding this comment.
📋 Upsun Dispatch Review: incremental · 5 files reviewed · no new issues · 5 still open
Outstanding from earlier reviews:
- #3652057652 — src/TokenParser/TypesTokenParser.php:40: Redundant construction and duplicated type state make the model wasteful and easy to desynchronize.
- #3653256238 — src/ExpressionParser.php:314: Duplicated conversion logic across parsers is easy to desynchronize as documentation handling evolves.
- #3659503446 — src/NodeVisitor/DocumentationNodeVisitor.php:38: Undocumented root-node assumption makes the visitor unsafe to reuse on subtrees.
- #3659503454 — src/NodeVisitor/DocumentationNodeVisitor.php:65: Stale AST references accumulate across compilations when traversal throws.
- #3682514990 — src/Node/NodeDocumentation.php:21: Misleading name invites incorrect assumptions if new call sites reuse it expecting replacement semantics.
Alternatives to #4870
To avoid BC breaks, I have another idea, using
##as a new syntax, a bit like/** */in PHP vs/* */."Documentation" is attached as metadata to the next relevant node:
Documentation comments can also describe variables declared with the
typestag:{% types { ## The unique identifier of the article id: 'string', ## Whether the article should be highlighted featured?: 'boolean', } %}Node visitors can access this metadata through
Node::getDocumentation(), allowing IDEs, static analyzers, and documentation generators to consume it without affecting template rendering. Documentation is preserved when visitors or optimizations replace nodes.Closes #4768
Closes #4870