1
0
Fork 0

also yield URIs to save memory

pull/451/head
Nicolas MURE 2017-08-10 00:06:53 +02:00
parent 8768b698d5
commit 8801edb7a2
No known key found for this signature in database
GPG Key ID: E5B036F9145C4CAA
4 changed files with 35 additions and 18 deletions

View File

@ -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 * @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 ($this->getIndexes() as $index) {
foreach ($index->getReferenceUris($fqn) as $ref) { foreach ($index->getReferenceUris($fqn) as $uri) {
$refs[] = $ref; yield $uri;
} }
} }
return $refs;
} }
} }

View File

@ -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 * @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;
}
} }
/** /**

View File

@ -63,10 +63,10 @@ interface ReadableIndex extends EmitterInterface
public function getDefinition(string $fqn, bool $globalFallback = false); 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 * @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;
} }

View File

@ -219,10 +219,9 @@ class TextDocument
return []; return [];
} }
} }
$refDocuments = yield Promise\all(array_map( $refDocuments = yield Promise\all(iterator_to_array(
[$this->documentLoader, 'getOrLoad'], $this->getOrLoadReferences($fqn))
$this->index->getReferenceUris($fqn) );
));
foreach ($refDocuments as $document) { foreach ($refDocuments as $document) {
$refs = $document->getReferenceNodesByFqn($fqn); $refs = $document->getReferenceNodesByFqn($fqn);
if ($refs !== null) { if ($refs !== null) {
@ -397,4 +396,17 @@ 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);
}
}
} }