Skip to content

Commit f23df4b

Browse files
committed
Add ArrayValue to searchForAutocompleting
Fixes N1ebieski#7
1 parent 599f0e4 commit f23df4b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

app/Parsers/ArrayCreationExpressionParser.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use App\Contexts\AbstractContext;
66
use App\Contexts\ArrayValue;
77
use Microsoft\PhpParser\MissingToken;
8+
use Microsoft\PhpParser\Node;
89
use Microsoft\PhpParser\Node\Expression\ArrayCreationExpression;
10+
use Microsoft\PhpParser\Node\Expression\CallExpression;
911

1012
class ArrayCreationExpressionParser extends AbstractParser
1113
{
@@ -14,9 +16,27 @@ class ArrayCreationExpressionParser extends AbstractParser
1416
*/
1517
protected AbstractContext $context;
1618

19+
private function isParentNode(Node $node, string $nodeClass): bool
20+
{
21+
if ($node->getParent() !== null) {
22+
if ($node->getParent() instanceof $nodeClass) {
23+
return true;
24+
}
25+
26+
return $this->isParentNode($node->getParent(), $nodeClass);
27+
}
28+
29+
return false;
30+
}
31+
1732
public function parse(ArrayCreationExpression $node)
1833
{
19-
$this->context->autocompleting = $node->closeParenOrBracket instanceof MissingToken;
34+
// If array is inside a method, for example Validator::validate(['
35+
// then we need to ignore autocompleting for ArrayValue because
36+
// priority is given to App\Contexts\MethodCall
37+
if (!$this->isParentNode($node, CallExpression::class)) {
38+
$this->context->autocompleting = $node->closeParenOrBracket instanceof MissingToken;
39+
}
2040

2141
return $this->context;
2242
}

0 commit comments

Comments
 (0)