|
11 | 11 | use Microsoft\PhpParser\Node\DelimitedList\ExpressionList;
|
12 | 12 | use Microsoft\PhpParser\Node\EnumCaseDeclaration;
|
13 | 13 | use Microsoft\PhpParser\Node\EnumMembers;
|
| 14 | +use Microsoft\PhpParser\Node\Expression; |
| 15 | +use Microsoft\PhpParser\Node\Expression\AssignmentExpression; |
14 | 16 | use Microsoft\PhpParser\Node\Expression\Variable;
|
15 | 17 | use Microsoft\PhpParser\Node\InterfaceMembers;
|
16 | 18 | use Microsoft\PhpParser\Node\MethodDeclaration;
|
@@ -141,21 +143,13 @@ private function buildNode(Node $node, string $source): ?DocumentSymbol
|
141 | 143 | }
|
142 | 144 |
|
143 | 145 | if ($node instanceof Variable) {
|
144 |
| - if ($node->getFirstAncestor(PropertyDeclaration::class)) { |
145 |
| - return new DocumentSymbol( |
146 |
| - (string)$node->getName(), |
147 |
| - SymbolKind::PROPERTY, |
148 |
| - new Range( |
149 |
| - PositionConverter::intByteOffsetToPosition($node->parent->getStartPosition(), $source), |
150 |
| - PositionConverter::intByteOffsetToPosition($node->parent->getEndPosition(), $source) |
151 |
| - ), |
152 |
| - new Range( |
153 |
| - PositionConverter::intByteOffsetToPosition($node->getStartPosition(), $source), |
154 |
| - PositionConverter::intByteOffsetToPosition($node->getEndPosition(), $source) |
155 |
| - ), |
156 |
| - children: [] |
157 |
| - ); |
158 |
| - } |
| 146 | + return $this->resolvePropertyVariable($node, $source); |
| 147 | + } |
| 148 | + |
| 149 | + if ($node instanceof AssignmentExpression) { |
| 150 | + /** @var Expression $left */ |
| 151 | + $left = $node->leftOperand; |
| 152 | + return $this->resolvePropertyVariable($left, $source); |
159 | 153 | }
|
160 | 154 |
|
161 | 155 | if ($node instanceof ConstElement) {
|
@@ -209,6 +203,30 @@ private function buildNode(Node $node, string $source): ?DocumentSymbol
|
209 | 203 | return null;
|
210 | 204 | }
|
211 | 205 |
|
| 206 | + |
| 207 | + private function resolvePropertyVariable(Node $node, string $source): ?DocumentSymbol |
| 208 | + { |
| 209 | + if (!$node instanceof Variable) { |
| 210 | + return null; |
| 211 | + } |
| 212 | + if (!$node->getFirstAncestor(PropertyDeclaration::class)) { |
| 213 | + return null; |
| 214 | + } |
| 215 | + return new DocumentSymbol( |
| 216 | + (string)$node->getName(), |
| 217 | + SymbolKind::PROPERTY, |
| 218 | + new Range( |
| 219 | + PositionConverter::intByteOffsetToPosition($node->parent->getStartPosition(), $source), |
| 220 | + PositionConverter::intByteOffsetToPosition($node->parent->getEndPosition(), $source) |
| 221 | + ), |
| 222 | + new Range( |
| 223 | + PositionConverter::intByteOffsetToPosition($node->getStartPosition(), $source), |
| 224 | + PositionConverter::intByteOffsetToPosition($node->getEndPosition(), $source) |
| 225 | + ), |
| 226 | + children: [] |
| 227 | + ); |
| 228 | + } |
| 229 | + |
212 | 230 | private function memberNodes(Node $node): Generator
|
213 | 231 | {
|
214 | 232 | return $node->getDescendantNodes(function (Node $node) {
|
|
0 commit comments