Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add ArrayValue to search for autocompleting #16

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

10 changes: 6 additions & 4 deletions 10 app/Contexts/AbstractContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ abstract class AbstractContext
{
public array $children = [];

public bool $isAbleToAutocomplete = false;

public bool $autocompleting = false;

protected array $freshObject;
Expand Down Expand Up @@ -48,20 +50,20 @@ public function flip()
public function findAutocompleting(?AbstractContext $context = null)
{
$context = $context ?? $this;
$result = $this->seachForAutocompleting($context, true);
$result = $this->searchForAutocompleting($context, true);
$lastResult = null;

while ($result !== null) {
$lastResult = $result;
$result = $this->seachForAutocompleting($result);
$result = $this->searchForAutocompleting($result);
}

return $lastResult;
}

protected function seachForAutocompleting(AbstractContext $context, $checkCurrent = false)
protected function searchForAutocompleting(AbstractContext $context, $checkCurrent = false)
{
if ($checkCurrent && $context->autocompleting && ($context instanceof MethodCall || $context instanceof ObjectValue)) {
if ($checkCurrent && $context->autocompleting && $context->isAbleToAutocomplete) {
return $context;
}

Expand Down
2 changes: 2 additions & 0 deletions 2 app/Contexts/MethodCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class MethodCall extends AbstractContext
{
public bool $isAbleToAutocomplete = true;

public ?string $methodName = null;

public ?string $className = null;
Expand Down
2 changes: 2 additions & 0 deletions 2 app/Contexts/ObjectValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class ObjectValue extends AbstractContext
{
public bool $isAbleToAutocomplete = true;

public ?string $className = null;

public Arguments $arguments;
Expand Down
10 changes: 10 additions & 0 deletions 10 app/Parsers/AbstractParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,14 @@ public function debug(...$messages)
echo $this->indent($message) . PHP_EOL;
}
}

protected function parentNodeIs(Node $node, array $nodeClasses): bool
{
if ($node->getParent() === null) {
return false;
}

return in_array(get_class($node->getParent()), $nodeClasses)
|| $this->parentNodeIs($node->getParent(), $nodeClasses);
}
}
9 changes: 9 additions & 0 deletions 9 app/Parsers/ArrayCreationExpressionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use App\Contexts\ArrayValue;
use Microsoft\PhpParser\MissingToken;
use Microsoft\PhpParser\Node\Expression\ArrayCreationExpression;
use Microsoft\PhpParser\Node\Expression\CallExpression;
use Microsoft\PhpParser\Node\Expression\ObjectCreationExpression;

class ArrayCreationExpressionParser extends AbstractParser
{
Expand All @@ -16,6 +18,13 @@ class ArrayCreationExpressionParser extends AbstractParser

public function parse(ArrayCreationExpression $node)
{
// If array is inside a method, for example Validator::validate(['
// then we need to ignore isAbleToAutocomplete for ArrayValue because
// priority is given to App\Contexts\MethodCall or App\Contexts\ObjectValue
if (!$this->parentNodeIs($node, [CallExpression::class, ObjectCreationExpression::class])) {
$this->context->isAbleToAutocomplete = true;
}

$this->context->autocompleting = $node->closeParenOrBracket instanceof MissingToken;

return $this->context;
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.