diff --git a/src/CompletionProvider.php b/src/CompletionProvider.php index eff8c33..8d0fb92 100644 --- a/src/CompletionProvider.php +++ b/src/CompletionProvider.php @@ -196,18 +196,15 @@ class CompletionProvider // $a->| // Multiple prefixes for all possible types - $prefixes = FqnUtilities\getFqnsFromType( + $fqns = FqnUtilities\getFqnsFromType( $this->definitionResolver->resolveExpressionNodeToType($node->dereferencableExpression) ); - // Include parent classes - $prefixes = iterator_to_array($this->expandParentFqns($prefixes), false); - - // Add the object access operator to only get members - foreach ($prefixes as &$prefix) { - $prefix .= '->'; + // Add the object access operator to only get members of all parents + $prefixes = []; + foreach ($this->expandParentFqns($fqns) as $prefix) { + $prefixes[] = $prefix . '->'; } - unset($prefix); // Collect all definitions that match any of the prefixes foreach ($this->index->getDefinitions() as $fqn => $def) { @@ -232,18 +229,15 @@ class CompletionProvider // TODO: $a::| // Resolve all possible types to FQNs - $prefixes = FqnUtilities\getFqnsFromType( + $fqns = FqnUtilities\getFqnsFromType( $classType = $this->definitionResolver->resolveExpressionNodeToType($scoped->scopeResolutionQualifier) ); - // Add parent classes - $prefixes = iterator_to_array($this->expandParentFqns($prefixes), false); - - // Append :: operator to only get static members - foreach ($prefixes as &$prefix) { - $prefix .= '::'; + // Append :: operator to only get static members of all parents + $prefixes = []; + foreach ($this->expandParentFqns($fqns) as $prefix) { + $prefixes[] = $prefix . '::'; } - unset($prefix); // Collect all definitions that match any of the prefixes foreach ($this->index->getDefinitions() as $fqn => $def) { @@ -388,7 +382,9 @@ class CompletionProvider yield $fqn; $def = $this->index->getDefinition($fqn); if ($def !== null) { - yield from $def->getAncestorFQNs($this->index); + foreach ($def->getAncestorDefinitions($this->index) as $name => $def) { + yield $name; + } } } } diff --git a/src/Definition.php b/src/Definition.php index 02afb62..514d1c0 100644 --- a/src/Definition.php +++ b/src/Definition.php @@ -105,16 +105,16 @@ class Definition public function getAncestorDefinitions(ReadableIndex $index, bool $includeSelf = false) { if ($includeSelf) { - yield $this; + yield $this->fqn => $this; } if (is_array($this->extends)) { // iterating once, storing the references and iterating again - // guarantees that closest definitions are returned first + // guarantees that closest definitions are yielded first $definitions = []; foreach ($this->extends as $fqn) { $def = $index->getDefinition($fqn); if ($def !== null) { - yield $def; + yield $def->fqn => $def; $definitions[] = $def; } } @@ -123,15 +123,4 @@ class Definition } } } - /** - * Gets the FQNs of all parent classes - * - * @return string[] - */ - public function getAncestorFQNs(ReadableIndex $index, bool $includeSelf = false) - { - foreach ($this->getAncestorDefinitions($index, $includeSelf) as $def) { - yield $def->fqn; - } - } } diff --git a/src/DefinitionResolver.php b/src/DefinitionResolver.php index 4483a6c..51c5955 100644 --- a/src/DefinitionResolver.php +++ b/src/DefinitionResolver.php @@ -672,7 +672,7 @@ class DefinitionResolver } $classDef = $this->index->getDefinition($classFqn); if ($classDef !== null) { - foreach ($classDef->getAncestorFQNs($this->index, true) as $fqn) { + foreach ($classDef->getAncestorDefinitions($this->index, true) as $fqn => $def) { $def = $this->index->getDefinition($fqn . $add); if ($def !== null) { if ($def->type instanceof Types\This) {