1
0
Fork 0
pull/451/head
Felix Becker 2017-11-18 14:53:18 -08:00
parent 3bda390c3d
commit b03950cb53
5 changed files with 35 additions and 48 deletions

View File

@ -221,7 +221,7 @@ 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) {
// Collect fqn definitions // Collect fqn definitions
foreach ($this->index->getDefinitionsForFqn($parentFqn) as $fqn => $def) { foreach ($this->index->getDescendantDefinitionsForFqn($parentFqn) as $fqn => $def) {
// Add the object access operator to only get members of all parents // Add the object access operator to only get members of all parents
$prefix = $parentFqn . '->'; $prefix = $parentFqn . '->';
if (substr($fqn, 0, strlen($prefix)) === $prefix && $def->isMember) { if (substr($fqn, 0, strlen($prefix)) === $prefix && $def->isMember) {
@ -251,7 +251,7 @@ 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) {
// Collect fqn definitions // Collect fqn definitions
foreach ($this->index->getDefinitionsForFqn($parentFqn) as $fqn => $def) { foreach ($this->index->getDescendantDefinitionsForFqn($parentFqn) as $fqn => $def) {
// Append :: operator to only get static members of all parents // Append :: operator to only get static members of all parents
$prefix = strtolower($parentFqn . '::'); $prefix = strtolower($parentFqn . '::');
if (substr(strtolower($fqn), 0, strlen($prefix)) === $prefix && $def->isMember) { if (substr(strtolower($fqn), 0, strlen($prefix)) === $prefix && $def->isMember) {

View File

@ -102,7 +102,7 @@ abstract class AbstractAggregateIndex implements ReadableIndex
* Returns a Generator providing an associative array [string => Definition] * Returns a Generator providing an associative array [string => Definition]
* that maps fully qualified symbol names to Definitions (global or not) * that maps fully qualified symbol names to Definitions (global or not)
* *
* @return \Generator providing Definition[] * @return \Generator yields Definition
*/ */
public function getDefinitions(): \Generator public function getDefinitions(): \Generator
{ {
@ -112,15 +112,15 @@ abstract class AbstractAggregateIndex implements ReadableIndex
} }
/** /**
* Returns a Generator providing the Definitions that are in the given FQN * Returns a Generator that yields all the descendant Definitions of a given FQN
* *
* @param string $fqn * @param string $fqn
* @return \Generator providing Definitions[] * @return \Generator yields Definition
*/ */
public function getDefinitionsForFqn(string $fqn): \Generator public function getDescendantDefinitionsForFqn(string $fqn): \Generator
{ {
foreach ($this->getIndexes() as $index) { foreach ($this->getIndexes() as $index) {
yield from $index->getDefinitionsForFqn($fqn); yield from $index->getDescendantDefinitionsForFqn($fqn);
} }
} }
@ -144,7 +144,7 @@ abstract class AbstractAggregateIndex implements ReadableIndex
* Returns a Generator providing all URIs in this index that reference a symbol * Returns a Generator providing all URIs in this index that reference a symbol
* *
* @param string $fqn The fully qualified name of the symbol * @param string $fqn The fully qualified name of the symbol
* @return \Generator providing string[] * @return \Generator yields string
*/ */
public function getReferenceUris(string $fqn): \Generator public function getReferenceUris(string $fqn): \Generator
{ {

View File

@ -99,7 +99,7 @@ class Index implements ReadableIndex, \Serializable
* Returns a Generator providing an associative array [string => Definition] * Returns a Generator providing an associative array [string => Definition]
* that maps fully qualified symbol names to Definitions (global or not) * that maps fully qualified symbol names to Definitions (global or not)
* *
* @return \Generator providing Definition[] * @return \Generator yields Definition
*/ */
public function getDefinitions(): \Generator public function getDefinitions(): \Generator
{ {
@ -107,12 +107,12 @@ class Index implements ReadableIndex, \Serializable
} }
/** /**
* Returns a Generator providing the Definitions that are in the given FQN * Returns a Generator that yields all the descendant Definitions of a given FQN
* *
* @param string $fqn * @param string $fqn
* @return \Generator providing Definitions[] * @return \Generator yields Definition
*/ */
public function getDefinitionsForFqn(string $fqn): \Generator public function getDescendantDefinitionsForFqn(string $fqn): \Generator
{ {
$parts = $this->splitFqn($fqn); $parts = $this->splitFqn($fqn);
if ('' === end($parts)) { if ('' === end($parts)) {
@ -188,7 +188,7 @@ class Index implements ReadableIndex, \Serializable
* Returns a Generator providing all URIs in this index that reference a symbol * Returns a Generator providing all URIs in this index that reference a symbol
* *
* @param string $fqn The fully qualified name of the symbol * @param string $fqn The fully qualified name of the symbol
* @return \Generator providing string[] * @return \Generator yields string
*/ */
public function getReferenceUris(string $fqn): \Generator public function getReferenceUris(string $fqn): \Generator
{ {
@ -280,9 +280,9 @@ class Index implements ReadableIndex, \Serializable
} }
/** /**
* Returns a Genrerator containing all the into the given $storage recursively. * Returns a Generator that yields all the Definitions in the given $storage recursively.
* The generator yields key => value pairs, eg * The generator yields key => value pairs, e.g.
* 'Psr\Log\LoggerInterface->log()' => $definition * `'Psr\Log\LoggerInterface->log()' => $definition`
* *
* @param array &$storage * @param array &$storage
* @param string $prefix (optional) * @param string $prefix (optional)
@ -319,12 +319,12 @@ class Index implements ReadableIndex, \Serializable
$parts = array_slice($parts, 1); $parts = array_slice($parts, 1);
} }
$parts[0] = '\\'.$parts[0]; $parts[0] = '\\' . $parts[0];
} }
// write back the backslashes prefixes for the other parts // write back the backslashes prefixes for the other parts
for ($i = 1; $i < count($parts); $i++) { for ($i = 1; $i < count($parts); $i++) {
$parts[$i] = '\\'.$parts[$i]; $parts[$i] = '\\' . $parts[$i];
} }
// split the last part in 2 parts at the operator // split the last part in 2 parts at the operator
@ -337,7 +337,7 @@ class Index implements ReadableIndex, \Serializable
// replace the last part by its pieces // replace the last part by its pieces
array_pop($parts); array_pop($parts);
$parts[] = $endParts[0]; $parts[] = $endParts[0];
$parts[] = $operator.$endParts[1]; $parts[] = $operator . $endParts[1];
break; break;
} }
} }
@ -382,8 +382,8 @@ class Index implements ReadableIndex, \Serializable
} }
/** /**
* Recusrive function which store the given definition in the given $storage * Recursive function that stores the given Definition in the given $storage array represented
* array represented as a tree matching the given $parts. * as a tree matching the given $parts.
* *
* @param int $level The current level of FQN part * @param int $level The current level of FQN part
* @param string[] $parts The splitted FQN * @param string[] $parts The splitted FQN
@ -408,11 +408,9 @@ class Index implements ReadableIndex, \Serializable
} }
/** /**
* Recusrive function which remove the definition matching the given $parts * Recursive function that removes the definition matching the given $parts from the given
* from the given $storage array. * $storage array. The function also looks up recursively to remove the parents of the
* The function also looks up recursively to remove the parents of the * definition which no longer has children to avoid to let empty arrays in the index.
* definition which no longer has children to avoid to let empty arrays
* in the index.
* *
* @param int $level The current level of FQN part * @param int $level The current level of FQN part
* @param string[] $parts The splitted FQN * @param string[] $parts The splitted FQN

View File

@ -33,17 +33,17 @@ interface ReadableIndex extends EmitterInterface
* Returns a Generator providing an associative array [string => Definition] * Returns a Generator providing an associative array [string => Definition]
* that maps fully qualified symbol names to Definitions (global or not) * that maps fully qualified symbol names to Definitions (global or not)
* *
* @return \Generator providing Definition[] * @return \Generator yields Definition
*/ */
public function getDefinitions(): \Generator; public function getDefinitions(): \Generator;
/** /**
* Returns a Generator providing the Definitions that are in the given FQN * Returns a Generator that yields all the descendant Definitions of a given FQN
* *
* @param string $fqn * @param string $fqn
* @return \Generator providing Definitions[] * @return \Generator yields Definition
*/ */
public function getDefinitionsForFqn(string $fqn): \Generator; public function getDescendantDefinitionsForFqn(string $fqn): \Generator;
/** /**
* Returns the Definition object by a specific FQN * Returns the Definition object by a specific FQN
@ -55,10 +55,10 @@ interface ReadableIndex extends EmitterInterface
public function getDefinition(string $fqn, bool $globalFallback = false); public function getDefinition(string $fqn, bool $globalFallback = false);
/** /**
* Returns a Generator providing all URIs in this index that reference a symbol * Returns a Generator that yields all URIs in this index that reference a symbol
* *
* @param string $fqn The fully qualified name of the symbol * @param string $fqn The fully qualified name of the symbol
* @return \Generator providing string[] * @return \Generator yields string
*/ */
public function getReferenceUris(string $fqn): \Generator; public function getReferenceUris(string $fqn): \Generator;
} }

View File

@ -220,9 +220,11 @@ class TextDocument
return []; return [];
} }
} }
$refDocuments = yield Promise\all(iterator_to_array( $refDocumentPromises = [];
$this->getOrLoadReferences($fqn) foreach ($this->index->getReferenceUris($fqn) as $uri) {
)); $refDocumentPromises[] = $this->documentLoader->getOrLoad($uri);
}
$refDocuments = yield Promise\all($refDocumentPromises);
foreach ($refDocuments as $document) { foreach ($refDocuments as $document) {
$refs = $document->getReferenceNodesByFqn($fqn); $refs = $document->getReferenceNodesByFqn($fqn);
if ($refs !== null) { if ($refs !== null) {
@ -398,17 +400,4 @@ class TextDocument
return [new SymbolLocationInformation($descriptor, $def->symbolInformation->location)]; return [new SymbolLocationInformation($descriptor, $def->symbolInformation->location)];
}); });
} }
/**
* Gets or loads the documents referencing the given FQN.
*
* @param string $fqn
* @return \Generator providing Promise
*/
private function getOrLoadReferences(string $fqn): \Generator
{
foreach ($this->index->getReferenceUris($fqn) as $ref) {
yield $this->documentLoader->getOrLoad($ref);
}
}
} }