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