From dd3b6dc7e838a07cdb17c304f54cb348a1caed40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20No=C3=A9=20Gonz=C3=A1lez?= Date: Tue, 13 Nov 2018 21:49:02 +0100 Subject: [PATCH] [FIX] Checked changes and tested again --- .vscode/settings.json | 9 ++++ .../completion/child_class_visibility.php | 53 ++++++++++++++++--- src/CompletionProvider.php | 22 ++++---- 3 files changed, 66 insertions(+), 18 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4897ad8..d85d680 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,4 +6,13 @@ }, "files.trimTrailingWhitespace": true, "files.eol": "\n", + + "files.exclude": { + "**/.git": true, + "**/.svn": true, + "**/.hg": true, + "**/CVS": true, + "**/.DS_Store": true, + "**/tests": false + } } diff --git a/fixtures/completion/child_class_visibility.php b/fixtures/completion/child_class_visibility.php index 44a177d..ebfaeaf 100644 --- a/fixtures/completion/child_class_visibility.php +++ b/fixtures/completion/child_class_visibility.php @@ -1,9 +1,50 @@ - } -} \ No newline at end of file + public function canSeeMethod() + { + $this-> + } +} + +class Foo extends Bar +{ + + public function getRandom() + { + $this->c; + return random_bytes(25); + } +} + +class Bar +{ + + private $test; + protected $seeme; + + public function __construct() + { + $this->test = 'Basic'; + } + + public function getTest() + { + return $this->test; + } + + private function cantSee() + { + + } + + protected function canSee($arg) + { + # code... + } +} + +$foo = new Foo(); +$foo->getRandom(); diff --git a/src/CompletionProvider.php b/src/CompletionProvider.php index f8f85bf..fc76e4e 100644 --- a/src/CompletionProvider.php +++ b/src/CompletionProvider.php @@ -159,7 +159,6 @@ class CompletionProvider ): CompletionList { // This can be made much more performant if the tree follows specific invariants. $node = $doc->getNodeAtPosition($pos); - // Get the node at the position under the cursor $offset = $node === null ? -1 : $pos->toOffset($node->getFileContents()); if ( @@ -248,18 +247,17 @@ class CompletionProvider $this->definitionResolver->resolveExpressionNodeToType($node->dereferencableExpression) ); $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) { - $prefixes[] = $prefix . '->'; - } - - // Collect all definitions that match any of the prefixes - foreach ($this->index->getDefinitions() as $fqn => $def) { - foreach ($prefixes as $prefix) { - if (substr($fqn, 0, strlen($prefix)) === $prefix && + // The FQNs of the symbol and its parents (eg the implemented interfaces) + foreach ($this->expandParentFqns($fqns) as $parentFqn) { + // Add the object access operator to only get members of all parents + $prefix = $parentFqn . '->'; + $prefixLen = strlen($prefix); + // Collect fqn definitions + foreach ($this->index->getChildDefinitionsForFqn($parentFqn) as $fqn => $def) { + if (substr($fqn, 0, $prefixLen) === $prefix && $def->isMember && - $def->isVisible($prefix, $prefixes[0], $isInMethodDeclaration)) { + $def->isVisible($prefix, $fqns[0] . '->', $isInMethodDeclaration) + ) { $list->items[] = CompletionItemFactory::fromDefinition($def); } }