Correct DependenciesIndex and add static complete
parent
ac75b511c8
commit
c5be9d0be5
|
@ -20,16 +20,29 @@ abstract class AbstractAggregateIndex implements ReadableIndex
|
|||
public function __construct()
|
||||
{
|
||||
foreach ($this->getIndexes() as $index) {
|
||||
$this->registerIndex($index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReadableIndex $index
|
||||
*/
|
||||
protected function registerIndex(ReadableIndex $index)
|
||||
{
|
||||
$index->on('complete', function () {
|
||||
if ($this->isComplete()) {
|
||||
$this->emit('complete');
|
||||
}
|
||||
});
|
||||
$index->on('static-complete', function () {
|
||||
if ($this->isStaticComplete()) {
|
||||
$this->emit('static-complete');
|
||||
}
|
||||
});
|
||||
$index->on('definition-added', function () {
|
||||
$this->emit('definition-added');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks this index as complete
|
||||
|
@ -43,6 +56,18 @@ abstract class AbstractAggregateIndex implements ReadableIndex
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks this index as complete for static definitions and references
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setStaticComplete()
|
||||
{
|
||||
foreach ($this->getIndexes() as $index) {
|
||||
$index->setStaticComplete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this index is complete
|
||||
*
|
||||
|
@ -58,6 +83,21 @@ abstract class AbstractAggregateIndex implements ReadableIndex
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this index is complete for static definitions or references
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isStaticComplete(): bool
|
||||
{
|
||||
foreach ($this->getIndexes() as $index) {
|
||||
if (!$index->isStaticComplete()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an associative array [string => Definition] that maps fully qualified symbol names
|
||||
* to Definitions
|
||||
|
|
|
@ -27,7 +27,9 @@ class DependenciesIndex extends AbstractAggregateIndex
|
|||
public function getDependencyIndex(string $packageName): Index
|
||||
{
|
||||
if (!isset($this->indexes[$packageName])) {
|
||||
$this->indexes[$packageName] = new Index;
|
||||
$index = new Index;
|
||||
$this->indexes[$packageName] = $index;
|
||||
$this->registerIndex($index);
|
||||
}
|
||||
return $this->indexes[$packageName];
|
||||
}
|
||||
|
|
|
@ -33,6 +33,11 @@ class Index implements ReadableIndex
|
|||
*/
|
||||
private $complete = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $staticComplete = false;
|
||||
|
||||
/**
|
||||
* Marks this index as complete
|
||||
*
|
||||
|
@ -44,6 +49,17 @@ class Index implements ReadableIndex
|
|||
$this->emit('complete');
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks this index as complete for static definitions and references
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setStaticComplete()
|
||||
{
|
||||
$this->complete = true;
|
||||
$this->emit('static-complete');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this index is complete
|
||||
*
|
||||
|
@ -54,6 +70,16 @@ class Index implements ReadableIndex
|
|||
return $this->complete;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this index is complete
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isStaticComplete(): bool
|
||||
{
|
||||
return $this->staticComplete;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an associative array [string => Definition] that maps fully qualified symbol names
|
||||
* to Definitions
|
||||
|
|
|
@ -10,6 +10,7 @@ use Sabre\Event\EmitterInterface;
|
|||
* The ReadableIndex interface provides methods to lookup definitions and references
|
||||
*
|
||||
* @event definition-added Emitted when a definition was added
|
||||
* @event static-complete Emitted when definitions and static references are complete
|
||||
* @event complete Emitted when the index is complete
|
||||
*/
|
||||
interface ReadableIndex extends EmitterInterface
|
||||
|
@ -21,6 +22,13 @@ interface ReadableIndex extends EmitterInterface
|
|||
*/
|
||||
public function isComplete(): bool;
|
||||
|
||||
/**
|
||||
* Returns true if definitions and static references are complete
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isStaticComplete(): bool;
|
||||
|
||||
/**
|
||||
* Returns an associative array [string => Definition] that maps fully qualified symbol names
|
||||
* to Definitions
|
||||
|
|
|
@ -316,8 +316,8 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
|||
|
||||
$startTime = microtime(true);
|
||||
|
||||
foreach (['Collecting definitions and static references', 'Collecting dynamic references'] as $run) {
|
||||
$this->client->window->logMessage(MessageType::INFO, $run);
|
||||
foreach (['Collecting definitions and static references', 'Collecting dynamic references'] as $run => $text) {
|
||||
$this->client->window->logMessage(MessageType::INFO, $text);
|
||||
foreach ($uris as $i => $uri) {
|
||||
if ($this->documentLoader->isOpen($uri)) {
|
||||
continue;
|
||||
|
@ -346,7 +346,11 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
|||
);
|
||||
}
|
||||
}
|
||||
if ($run === 0) {
|
||||
$this->projectIndex->setStaticComplete();
|
||||
} else {
|
||||
$this->projectIndex->setComplete();
|
||||
}
|
||||
$duration = (int)(microtime(true) - $startTime);
|
||||
$mem = (int)(memory_get_usage(true) / (1024 * 1024));
|
||||
$this->client->window->logMessage(
|
||||
|
|
|
@ -314,7 +314,6 @@ class TextDocument
|
|||
}
|
||||
$definedFqn = DefinitionResolver::getDefinedFqn($node);
|
||||
while (true) {
|
||||
fwrite(STDERR, "searching for definition\n");
|
||||
if ($definedFqn) {
|
||||
// Support hover for definitions
|
||||
$def = $this->index->getDefinition($definedFqn);
|
||||
|
|
|
@ -67,9 +67,9 @@ class Workspace
|
|||
public function symbol(string $query): Promise
|
||||
{
|
||||
return coroutine(function () use ($query) {
|
||||
// Wait until indexing finished
|
||||
// Wait until indexing for definitions finished
|
||||
if (!$this->index->isComplete()) {
|
||||
yield waitForEvent($this->index, 'complete');
|
||||
yield waitForEvent($this->index, 'static-complete');
|
||||
}
|
||||
$symbols = [];
|
||||
foreach ($this->index->getDefinitions() as $fqn => $definition) {
|
||||
|
|
Loading…
Reference in New Issue