use Ds\Set
parent
9dc1656592
commit
bc07c19957
|
@ -28,6 +28,7 @@
|
|||
"jetbrains/phpstorm-stubs": "dev-master",
|
||||
"microsoft/tolerant-php-parser": "0.0.*",
|
||||
"netresearch/jsonmapper": "^1.0",
|
||||
"php-ds/php-ds": "^1.2",
|
||||
"phpdocumentor/reflection-docblock": "^4.0.0",
|
||||
"psr/log": "^1.0",
|
||||
"sabre/event": "^5.0",
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<?php
|
||||
declare(strict_types = 1);
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LanguageServer\Index;
|
||||
|
||||
use Ds\Set;
|
||||
use LanguageServer\Definition;
|
||||
use Sabre\Event\EmitterTrait;
|
||||
|
||||
|
@ -36,7 +37,7 @@ class Index implements ReadableIndex, \Serializable
|
|||
* An associative array that maps fully qualified symbol names
|
||||
* to arrays of document URIs that reference the symbol
|
||||
*
|
||||
* @var string[][]
|
||||
* @var Set[]
|
||||
*/
|
||||
private $references = [];
|
||||
|
||||
|
@ -131,9 +132,9 @@ class Index implements ReadableIndex, \Serializable
|
|||
continue;
|
||||
}
|
||||
if ($item instanceof Definition) {
|
||||
yield $fqn.$name => $item;
|
||||
yield $fqn . $name => $item;
|
||||
} elseif (is_array($item) && isset($item[''])) {
|
||||
yield $fqn.$name => $item[''];
|
||||
yield $fqn . $name => $item[''];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -200,16 +201,18 @@ class Index implements ReadableIndex, \Serializable
|
|||
*/
|
||||
public function getReferenceUris(string $fqn): \Generator
|
||||
{
|
||||
foreach ($this->references[$fqn] ?? [] as $uri) {
|
||||
if ($this->references[$fqn]) {
|
||||
foreach ($this->references[$fqn] as $uri) {
|
||||
yield $uri;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For test use.
|
||||
* Returns all references, keyed by fqn.
|
||||
*
|
||||
* @return string[][]
|
||||
* @return Set[]
|
||||
*/
|
||||
public function getReferences(): array
|
||||
{
|
||||
|
@ -225,12 +228,9 @@ class Index implements ReadableIndex, \Serializable
|
|||
public function addReferenceUri(string $fqn, string $uri)
|
||||
{
|
||||
if (!isset($this->references[$fqn])) {
|
||||
$this->references[$fqn] = [];
|
||||
}
|
||||
// TODO: use DS\Set instead of searching array
|
||||
if (array_search($uri, $this->references[$fqn], true) === false) {
|
||||
$this->references[$fqn][] = $uri;
|
||||
$this->references[$fqn] = new Set();
|
||||
}
|
||||
$this->references[$fqn]->add($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,11 +245,7 @@ class Index implements ReadableIndex, \Serializable
|
|||
if (!isset($this->references[$fqn])) {
|
||||
return;
|
||||
}
|
||||
$index = array_search($fqn, $this->references[$fqn], true);
|
||||
if ($index === false) {
|
||||
return;
|
||||
}
|
||||
array_splice($this->references[$fqn], $index, 1);
|
||||
$this->references[$fqn]->remove($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -299,9 +295,9 @@ class Index implements ReadableIndex, \Serializable
|
|||
{
|
||||
foreach ($storage as $key => $value) {
|
||||
if (!is_array($value)) {
|
||||
yield $prefix.$key => $value;
|
||||
yield $prefix . $key => $value;
|
||||
} else {
|
||||
yield from $this->yieldDefinitionsRecursively($value, $prefix.$key);
|
||||
yield from $this->yieldDefinitionsRecursively($value, $prefix . $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue