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