also yield URIs to save memory
parent
8768b698d5
commit
8801edb7a2
|
@ -160,19 +160,17 @@ abstract class AbstractAggregateIndex implements ReadableIndex
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns 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
|
||||
* @return string[]
|
||||
* @return \Generator providing string[]
|
||||
*/
|
||||
public function getReferenceUris(string $fqn): array
|
||||
public function getReferenceUris(string $fqn): \Generator
|
||||
{
|
||||
$refs = [];
|
||||
foreach ($this->getIndexes() as $index) {
|
||||
foreach ($index->getReferenceUris($fqn) as $ref) {
|
||||
$refs[] = $ref;
|
||||
foreach ($index->getReferenceUris($fqn) as $uri) {
|
||||
yield $uri;
|
||||
}
|
||||
}
|
||||
return $refs;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,14 +197,21 @@ class Index implements ReadableIndex, \Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns 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
|
||||
* @return string[]
|
||||
* @return \Generator providing string[]
|
||||
*/
|
||||
public function getReferenceUris(string $fqn): array
|
||||
public function getReferenceUris(string $fqn): \Generator
|
||||
{
|
||||
return $this->references[$fqn] ?? [];
|
||||
$uris = isset($this->references[$fqn])
|
||||
? $this->references[$fqn]
|
||||
: []
|
||||
;
|
||||
|
||||
foreach ($uris as $uri) {
|
||||
yield $uri;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -63,10 +63,10 @@ interface ReadableIndex extends EmitterInterface
|
|||
public function getDefinition(string $fqn, bool $globalFallback = false);
|
||||
|
||||
/**
|
||||
* Returns 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
|
||||
* @return string[]
|
||||
* @return \Generator providing string[]
|
||||
*/
|
||||
public function getReferenceUris(string $fqn): array;
|
||||
public function getReferenceUris(string $fqn): \Generator;
|
||||
}
|
||||
|
|
|
@ -219,10 +219,9 @@ class TextDocument
|
|||
return [];
|
||||
}
|
||||
}
|
||||
$refDocuments = yield Promise\all(array_map(
|
||||
[$this->documentLoader, 'getOrLoad'],
|
||||
$this->index->getReferenceUris($fqn)
|
||||
));
|
||||
$refDocuments = yield Promise\all(iterator_to_array(
|
||||
$this->getOrLoadReferences($fqn))
|
||||
);
|
||||
foreach ($refDocuments as $document) {
|
||||
$refs = $document->getReferenceNodesByFqn($fqn);
|
||||
if ($refs !== null) {
|
||||
|
@ -397,4 +396,17 @@ class TextDocument
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue