perf: get direct children
parent
91ca99a867
commit
fa67f84b73
|
@ -220,11 +220,12 @@ class CompletionProvider
|
|||
|
||||
// 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->getDescendantDefinitionsForFqn($parentFqn) as $fqn => $def) {
|
||||
// Add the object access operator to only get members of all parents
|
||||
$prefix = $parentFqn . '->';
|
||||
if (substr($fqn, 0, strlen($prefix)) === $prefix && $def->isMember) {
|
||||
foreach ($this->index->getChildDefinitionsForFqn($parentFqn) as $fqn => $def) {
|
||||
if (substr($fqn, 0, $prefixLen) === $prefix && $def->isMember) {
|
||||
$list->items[] = CompletionItem::fromDefinition($def);
|
||||
}
|
||||
}
|
||||
|
@ -250,11 +251,12 @@ class CompletionProvider
|
|||
|
||||
// The FQNs of the symbol and its parents (eg the implemented interfaces)
|
||||
foreach ($this->expandParentFqns($fqns) as $parentFqn) {
|
||||
// Append :: operator to only get static members of all parents
|
||||
$prefix = strtolower($parentFqn . '::');
|
||||
$prefixLen = strlen($prefix);
|
||||
// Collect fqn definitions
|
||||
foreach ($this->index->getDescendantDefinitionsForFqn($parentFqn) as $fqn => $def) {
|
||||
// Append :: operator to only get static members of all parents
|
||||
$prefix = strtolower($parentFqn . '::');
|
||||
if (substr(strtolower($fqn), 0, strlen($prefix)) === $prefix && $def->isMember) {
|
||||
foreach ($this->index->getChildDefinitionsForFqn($parentFqn) as $fqn => $def) {
|
||||
if (substr(strtolower($fqn), 0, $prefixLen) === $prefix && $def->isMember) {
|
||||
$list->items[] = CompletionItem::fromDefinition($def);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,15 +112,15 @@ abstract class AbstractAggregateIndex implements ReadableIndex
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a Generator that yields all the descendant Definitions of a given FQN
|
||||
* Returns a Generator that yields all the direct child Definitions of a given FQN
|
||||
*
|
||||
* @param string $fqn
|
||||
* @return \Generator yields Definition
|
||||
*/
|
||||
public function getDescendantDefinitionsForFqn(string $fqn): \Generator
|
||||
public function getChildDefinitionsForFqn(string $fqn): \Generator
|
||||
{
|
||||
foreach ($this->getIndexes() as $index) {
|
||||
yield from $index->getDescendantDefinitionsForFqn($fqn);
|
||||
yield from $index->getChildDefinitionsForFqn($fqn);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -107,12 +107,12 @@ class Index implements ReadableIndex, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a Generator that yields all the descendant Definitions of a given FQN
|
||||
* Returns a Generator that yields all the direct child Definitions of a given FQN
|
||||
*
|
||||
* @param string $fqn
|
||||
* @return \Generator yields Definition
|
||||
*/
|
||||
public function getDescendantDefinitionsForFqn(string $fqn): \Generator
|
||||
public function getChildDefinitionsForFqn(string $fqn): \Generator
|
||||
{
|
||||
$parts = $this->splitFqn($fqn);
|
||||
if ('' === end($parts)) {
|
||||
|
@ -122,11 +122,15 @@ class Index implements ReadableIndex, \Serializable
|
|||
}
|
||||
|
||||
$result = $this->getIndexValue($parts, $this->definitions);
|
||||
|
||||
if ($result instanceof Definition) {
|
||||
yield $fqn => $result;
|
||||
} elseif (is_array($result)) {
|
||||
yield from $this->yieldDefinitionsRecursively($result, $fqn);
|
||||
if (!$result) {
|
||||
return;
|
||||
}
|
||||
foreach ($result as $name => $item) {
|
||||
// Don't yield the parent
|
||||
if ($name === '') {
|
||||
continue;
|
||||
}
|
||||
yield $fqn.$name => $item;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -374,7 +378,7 @@ class Index implements ReadableIndex, \Serializable
|
|||
|
||||
$parts = array_slice($parts, 1);
|
||||
// we've reached the last provided part
|
||||
if (0 === count($parts)) {
|
||||
if (empty($parts)) {
|
||||
return $storage[$part];
|
||||
}
|
||||
|
||||
|
|
|
@ -38,12 +38,12 @@ interface ReadableIndex extends EmitterInterface
|
|||
public function getDefinitions(): \Generator;
|
||||
|
||||
/**
|
||||
* Returns a Generator that yields all the descendant Definitions of a given FQN
|
||||
* Returns a Generator that yields all the direct child Definitions of a given FQN
|
||||
*
|
||||
* @param string $fqn
|
||||
* @return \Generator yields Definition
|
||||
*/
|
||||
public function getDescendantDefinitionsForFqn(string $fqn): \Generator;
|
||||
public function getChildDefinitionsForFqn(string $fqn): \Generator;
|
||||
|
||||
/**
|
||||
* Returns the Definition object by a specific FQN
|
||||
|
|
Loading…
Reference in New Issue