Skip to content

Commit b03950c

Browse files
committed
Cleanup
1 parent 3bda390 commit b03950c

File tree

5 files changed

+35
-48
lines changed

5 files changed

+35
-48
lines changed

src/CompletionProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function provideCompletion(PhpDocument $doc, Position $pos, CompletionCon
221221
// The FQNs of the symbol and its parents (eg the implemented interfaces)
222222
foreach ($this->expandParentFqns($fqns) as $parentFqn) {
223223
// Collect fqn definitions
224-
foreach ($this->index->getDefinitionsForFqn($parentFqn) as $fqn => $def) {
224+
foreach ($this->index->getDescendantDefinitionsForFqn($parentFqn) as $fqn => $def) {
225225
// Add the object access operator to only get members of all parents
226226
$prefix = $parentFqn . '->';
227227
if (substr($fqn, 0, strlen($prefix)) === $prefix && $def->isMember) {
@@ -251,7 +251,7 @@ public function provideCompletion(PhpDocument $doc, Position $pos, CompletionCon
251251
// The FQNs of the symbol and its parents (eg the implemented interfaces)
252252
foreach ($this->expandParentFqns($fqns) as $parentFqn) {
253253
// Collect fqn definitions
254-
foreach ($this->index->getDefinitionsForFqn($parentFqn) as $fqn => $def) {
254+
foreach ($this->index->getDescendantDefinitionsForFqn($parentFqn) as $fqn => $def) {
255255
// Append :: operator to only get static members of all parents
256256
$prefix = strtolower($parentFqn . '::');
257257
if (substr(strtolower($fqn), 0, strlen($prefix)) === $prefix && $def->isMember) {

src/Index/AbstractAggregateIndex.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function isStaticComplete(): bool
102102
* Returns a Generator providing an associative array [string => Definition]
103103
* that maps fully qualified symbol names to Definitions (global or not)
104104
*
105-
* @return \Generator providing Definition[]
105+
* @return \Generator yields Definition
106106
*/
107107
public function getDefinitions(): \Generator
108108
{
@@ -112,15 +112,15 @@ public function getDefinitions(): \Generator
112112
}
113113

114114
/**
115-
* Returns a Generator providing the Definitions that are in the given FQN
115+
* Returns a Generator that yields all the descendant Definitions of a given FQN
116116
*
117117
* @param string $fqn
118-
* @return \Generator providing Definitions[]
118+
* @return \Generator yields Definition
119119
*/
120-
public function getDefinitionsForFqn(string $fqn): \Generator
120+
public function getDescendantDefinitionsForFqn(string $fqn): \Generator
121121
{
122122
foreach ($this->getIndexes() as $index) {
123-
yield from $index->getDefinitionsForFqn($fqn);
123+
yield from $index->getDescendantDefinitionsForFqn($fqn);
124124
}
125125
}
126126

@@ -144,7 +144,7 @@ public function getDefinition(string $fqn, bool $globalFallback = false)
144144
* Returns a Generator providing all URIs in this index that reference a symbol
145145
*
146146
* @param string $fqn The fully qualified name of the symbol
147-
* @return \Generator providing string[]
147+
* @return \Generator yields string
148148
*/
149149
public function getReferenceUris(string $fqn): \Generator
150150
{

src/Index/Index.php

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,20 @@ public function isStaticComplete(): bool
9999
* Returns a Generator providing an associative array [string => Definition]
100100
* that maps fully qualified symbol names to Definitions (global or not)
101101
*
102-
* @return \Generator providing Definition[]
102+
* @return \Generator yields Definition
103103
*/
104104
public function getDefinitions(): \Generator
105105
{
106106
yield from $this->yieldDefinitionsRecursively($this->definitions);
107107
}
108108

109109
/**
110-
* Returns a Generator providing the Definitions that are in the given FQN
110+
* Returns a Generator that yields all the descendant Definitions of a given FQN
111111
*
112112
* @param string $fqn
113-
* @return \Generator providing Definitions[]
113+
* @return \Generator yields Definition
114114
*/
115-
public function getDefinitionsForFqn(string $fqn): \Generator
115+
public function getDescendantDefinitionsForFqn(string $fqn): \Generator
116116
{
117117
$parts = $this->splitFqn($fqn);
118118
if ('' === end($parts)) {
@@ -188,7 +188,7 @@ public function removeDefinition(string $fqn)
188188
* Returns a Generator providing all URIs in this index that reference a symbol
189189
*
190190
* @param string $fqn The fully qualified name of the symbol
191-
* @return \Generator providing string[]
191+
* @return \Generator yields string
192192
*/
193193
public function getReferenceUris(string $fqn): \Generator
194194
{
@@ -280,9 +280,9 @@ public function serialize()
280280
}
281281

282282
/**
283-
* Returns a Genrerator containing all the into the given $storage recursively.
284-
* The generator yields key => value pairs, eg
285-
* 'Psr\Log\LoggerInterface->log()' => $definition
283+
* Returns a Generator that yields all the Definitions in the given $storage recursively.
284+
* The generator yields key => value pairs, e.g.
285+
* `'Psr\Log\LoggerInterface->log()' => $definition`
286286
*
287287
* @param array &$storage
288288
* @param string $prefix (optional)
@@ -319,12 +319,12 @@ private function splitFqn(string $fqn): array
319319
$parts = array_slice($parts, 1);
320320
}
321321

322-
$parts[0] = '\\'.$parts[0];
322+
$parts[0] = '\\' . $parts[0];
323323
}
324324

325325
// write back the backslashes prefixes for the other parts
326326
for ($i = 1; $i < count($parts); $i++) {
327-
$parts[$i] = '\\'.$parts[$i];
327+
$parts[$i] = '\\' . $parts[$i];
328328
}
329329

330330
// split the last part in 2 parts at the operator
@@ -337,7 +337,7 @@ private function splitFqn(string $fqn): array
337337
// replace the last part by its pieces
338338
array_pop($parts);
339339
$parts[] = $endParts[0];
340-
$parts[] = $operator.$endParts[1];
340+
$parts[] = $operator . $endParts[1];
341341
break;
342342
}
343343
}
@@ -382,8 +382,8 @@ private function getIndexValue(array $parts, array &$storage)
382382
}
383383

384384
/**
385-
* Recusrive function which store the given definition in the given $storage
386-
* array represented as a tree matching the given $parts.
385+
* Recursive function that stores the given Definition in the given $storage array represented
386+
* as a tree matching the given $parts.
387387
*
388388
* @param int $level The current level of FQN part
389389
* @param string[] $parts The splitted FQN
@@ -408,11 +408,9 @@ private function indexDefinition(int $level, array $parts, array &$storage, Defi
408408
}
409409

410410
/**
411-
* Recusrive function which remove the definition matching the given $parts
412-
* from the given $storage array.
413-
* The function also looks up recursively to remove the parents of the
414-
* definition which no longer has children to avoid to let empty arrays
415-
* in the index.
411+
* Recursive function that removes the definition matching the given $parts from the given
412+
* $storage array. The function also looks up recursively to remove the parents of the
413+
* definition which no longer has children to avoid to let empty arrays in the index.
416414
*
417415
* @param int $level The current level of FQN part
418416
* @param string[] $parts The splitted FQN

src/Index/ReadableIndex.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ public function isStaticComplete(): bool;
3333
* Returns a Generator providing an associative array [string => Definition]
3434
* that maps fully qualified symbol names to Definitions (global or not)
3535
*
36-
* @return \Generator providing Definition[]
36+
* @return \Generator yields Definition
3737
*/
3838
public function getDefinitions(): \Generator;
3939

4040
/**
41-
* Returns a Generator providing the Definitions that are in the given FQN
41+
* Returns a Generator that yields all the descendant Definitions of a given FQN
4242
*
4343
* @param string $fqn
44-
* @return \Generator providing Definitions[]
44+
* @return \Generator yields Definition
4545
*/
46-
public function getDefinitionsForFqn(string $fqn): \Generator;
46+
public function getDescendantDefinitionsForFqn(string $fqn): \Generator;
4747

4848
/**
4949
* Returns the Definition object by a specific FQN
@@ -55,10 +55,10 @@ public function getDefinitionsForFqn(string $fqn): \Generator;
5555
public function getDefinition(string $fqn, bool $globalFallback = false);
5656

5757
/**
58-
* Returns a Generator providing all URIs in this index that reference a symbol
58+
* Returns a Generator that yields all URIs in this index that reference a symbol
5959
*
6060
* @param string $fqn The fully qualified name of the symbol
61-
* @return \Generator providing string[]
61+
* @return \Generator yields string
6262
*/
6363
public function getReferenceUris(string $fqn): \Generator;
6464
}

src/Server/TextDocument.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,11 @@ public function references(
220220
return [];
221221
}
222222
}
223-
$refDocuments = yield Promise\all(iterator_to_array(
224-
$this->getOrLoadReferences($fqn)
225-
));
223+
$refDocumentPromises = [];
224+
foreach ($this->index->getReferenceUris($fqn) as $uri) {
225+
$refDocumentPromises[] = $this->documentLoader->getOrLoad($uri);
226+
}
227+
$refDocuments = yield Promise\all($refDocumentPromises);
226228
foreach ($refDocuments as $document) {
227229
$refs = $document->getReferenceNodesByFqn($fqn);
228230
if ($refs !== null) {
@@ -398,17 +400,4 @@ public function xdefinition(TextDocumentIdentifier $textDocument, Position $posi
398400
return [new SymbolLocationInformation($descriptor, $def->symbolInformation->location)];
399401
});
400402
}
401-
402-
/**
403-
* Gets or loads the documents referencing the given FQN.
404-
*
405-
* @param string $fqn
406-
* @return \Generator providing Promise
407-
*/
408-
private function getOrLoadReferences(string $fqn): \Generator
409-
{
410-
foreach ($this->index->getReferenceUris($fqn) as $ref) {
411-
yield $this->documentLoader->getOrLoad($ref);
412-
}
413-
}
414403
}

0 commit comments

Comments
 (0)