From d1bdcbd173ac2dd83b9429a4cd5ef82f7b0d255a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20No=C3=A9=20Gonz=C3=A1lez?= Date: Sat, 10 Nov 2018 13:40:55 +0100 Subject: [PATCH] Resolving node ancestor in the CompletionProvider, so it's resolved outside the loop --- src/CompletionProvider.php | 5 +++-- src/Definition.php | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/CompletionProvider.php b/src/CompletionProvider.php index fa6d54f..4a87f1d 100644 --- a/src/CompletionProvider.php +++ b/src/CompletionProvider.php @@ -237,6 +237,7 @@ class CompletionProvider $this->definitionResolver->resolveExpressionNodeToType($node->dereferencableExpression) ); $start = microtime(true); + $isInMethodDeclaration = null !== $node->getFirstAncestor(\Microsoft\PhpParser\Node\MethodDeclaration::class); // Add the object access operator to only get members of all parents $prefixes = []; foreach ($this->expandParentFqns($fqns) as $prefix) { @@ -248,8 +249,8 @@ class CompletionProvider foreach ($prefixes as $prefix) { if (substr($fqn, 0, strlen($prefix)) === $prefix && $def->isMember && - $def->isVisible($prefix, $prefixes[0], $node)) { - $list->items[] = CompletionItem::fromDefinition($def); + $def->isVisible($prefix, $prefixes[0], $isInMethodDeclaration)) { + $list->items[] = CompletionItemFactory::fromDefinition($def); } } } diff --git a/src/Definition.php b/src/Definition.php index 4b6239d..39636bb 100644 --- a/src/Definition.php +++ b/src/Definition.php @@ -136,13 +136,15 @@ class Definition /** * Checks the definition's visibility. + * @param string $match Owner of the FQNS + * @param string $caller Descendant of the FQNS owner + * @param bool $isInMethodDeclaration checking if the call is from inside a + * method * @return bool */ - public function isVisible(string $match, string $caller, \Microsoft\PhpParser\Node $node): bool - { - $ancestor = $node->getFirstAncestor(\Microsoft\PhpParser\Node\MethodDeclaration::class); - - if ($ancestor) { + public function isVisible(string $match, string $caller, bool $isInMethodDeclaration): bool + { + if ($isInMethodDeclaration) { if ($match !== $caller && $this->isPrivate()) { return false; }