removed getAncestorFQNs in favor of yielding fqn keys
parent
51c0a94a21
commit
f1188aa658
|
@ -196,18 +196,15 @@ class CompletionProvider
|
||||||
// $a->|
|
// $a->|
|
||||||
|
|
||||||
// Multiple prefixes for all possible types
|
// Multiple prefixes for all possible types
|
||||||
$prefixes = FqnUtilities\getFqnsFromType(
|
$fqns = FqnUtilities\getFqnsFromType(
|
||||||
$this->definitionResolver->resolveExpressionNodeToType($node->dereferencableExpression)
|
$this->definitionResolver->resolveExpressionNodeToType($node->dereferencableExpression)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Include parent classes
|
// Add the object access operator to only get members of all parents
|
||||||
$prefixes = iterator_to_array($this->expandParentFqns($prefixes), false);
|
$prefixes = [];
|
||||||
|
foreach ($this->expandParentFqns($fqns) as $prefix) {
|
||||||
// Add the object access operator to only get members
|
$prefixes[] = $prefix . '->';
|
||||||
foreach ($prefixes as &$prefix) {
|
|
||||||
$prefix .= '->';
|
|
||||||
}
|
}
|
||||||
unset($prefix);
|
|
||||||
|
|
||||||
// Collect all definitions that match any of the prefixes
|
// Collect all definitions that match any of the prefixes
|
||||||
foreach ($this->index->getDefinitions() as $fqn => $def) {
|
foreach ($this->index->getDefinitions() as $fqn => $def) {
|
||||||
|
@ -232,18 +229,15 @@ class CompletionProvider
|
||||||
// TODO: $a::|
|
// TODO: $a::|
|
||||||
|
|
||||||
// Resolve all possible types to FQNs
|
// Resolve all possible types to FQNs
|
||||||
$prefixes = FqnUtilities\getFqnsFromType(
|
$fqns = FqnUtilities\getFqnsFromType(
|
||||||
$classType = $this->definitionResolver->resolveExpressionNodeToType($scoped->scopeResolutionQualifier)
|
$classType = $this->definitionResolver->resolveExpressionNodeToType($scoped->scopeResolutionQualifier)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add parent classes
|
// Append :: operator to only get static members of all parents
|
||||||
$prefixes = iterator_to_array($this->expandParentFqns($prefixes), false);
|
$prefixes = [];
|
||||||
|
foreach ($this->expandParentFqns($fqns) as $prefix) {
|
||||||
// Append :: operator to only get static members
|
$prefixes[] = $prefix . '::';
|
||||||
foreach ($prefixes as &$prefix) {
|
|
||||||
$prefix .= '::';
|
|
||||||
}
|
}
|
||||||
unset($prefix);
|
|
||||||
|
|
||||||
// Collect all definitions that match any of the prefixes
|
// Collect all definitions that match any of the prefixes
|
||||||
foreach ($this->index->getDefinitions() as $fqn => $def) {
|
foreach ($this->index->getDefinitions() as $fqn => $def) {
|
||||||
|
@ -388,7 +382,9 @@ class CompletionProvider
|
||||||
yield $fqn;
|
yield $fqn;
|
||||||
$def = $this->index->getDefinition($fqn);
|
$def = $this->index->getDefinition($fqn);
|
||||||
if ($def !== null) {
|
if ($def !== null) {
|
||||||
yield from $def->getAncestorFQNs($this->index);
|
foreach ($def->getAncestorDefinitions($this->index) as $name => $def) {
|
||||||
|
yield $name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,16 +105,16 @@ class Definition
|
||||||
public function getAncestorDefinitions(ReadableIndex $index, bool $includeSelf = false)
|
public function getAncestorDefinitions(ReadableIndex $index, bool $includeSelf = false)
|
||||||
{
|
{
|
||||||
if ($includeSelf) {
|
if ($includeSelf) {
|
||||||
yield $this;
|
yield $this->fqn => $this;
|
||||||
}
|
}
|
||||||
if (is_array($this->extends)) {
|
if (is_array($this->extends)) {
|
||||||
// iterating once, storing the references and iterating again
|
// iterating once, storing the references and iterating again
|
||||||
// guarantees that closest definitions are returned first
|
// guarantees that closest definitions are yielded first
|
||||||
$definitions = [];
|
$definitions = [];
|
||||||
foreach ($this->extends as $fqn) {
|
foreach ($this->extends as $fqn) {
|
||||||
$def = $index->getDefinition($fqn);
|
$def = $index->getDefinition($fqn);
|
||||||
if ($def !== null) {
|
if ($def !== null) {
|
||||||
yield $def;
|
yield $def->fqn => $def;
|
||||||
$definitions[] = $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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -672,7 +672,7 @@ class DefinitionResolver
|
||||||
}
|
}
|
||||||
$classDef = $this->index->getDefinition($classFqn);
|
$classDef = $this->index->getDefinition($classFqn);
|
||||||
if ($classDef !== null) {
|
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);
|
$def = $this->index->getDefinition($fqn . $add);
|
||||||
if ($def !== null) {
|
if ($def !== null) {
|
||||||
if ($def->type instanceof Types\This) {
|
if ($def->type instanceof Types\This) {
|
||||||
|
|
Loading…
Reference in New Issue