1
0
Fork 0

Index twice to collect dynamic references (#206)

pull/189/head^2
Felix Becker 2016-12-13 02:11:29 +01:00 committed by GitHub
parent a7d77d844e
commit d7fc9e0425
2 changed files with 42 additions and 37 deletions

View File

@ -238,42 +238,43 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
$startTime = microtime(true); $startTime = microtime(true);
// Parse PHP files foreach (['Collecting definitions and static references', 'Collecting dynamic references'] as $run) {
foreach ($uris as $i => $uri) { $this->client->window->logMessage(MessageType::INFO, $run);
if ($this->documentLoader->isOpen($uri)) { foreach ($uris as $i => $uri) {
continue; if ($this->documentLoader->isOpen($uri)) {
} continue;
// Give LS to the chance to handle requests while indexing
yield timeout();
$this->client->window->logMessage(
MessageType::LOG,
"Parsing file $i/$count: {$uri}"
);
try {
$document = yield $this->documentLoader->load($uri);
if (!$document->isVendored()) {
$this->client->textDocument->publishDiagnostics($uri, $document->getDiagnostics());
} }
} catch (ContentTooLargeException $e) {
$this->client->window->logMessage(
MessageType::INFO,
"Ignoring file {$uri} because it exceeds size limit of {$e->limit} bytes ({$e->size})"
);
} catch (Exception $e) {
$this->client->window->logMessage(
MessageType::ERROR,
"Error parsing file {$uri}: " . (string)$e
);
}
}
$duration = (int)(microtime(true) - $startTime); // Give LS to the chance to handle requests while indexing
$mem = (int)(memory_get_usage(true) / (1024 * 1024)); yield timeout();
$this->client->window->logMessage( $this->client->window->logMessage(
MessageType::INFO, MessageType::LOG,
"All $count PHP files parsed in $duration seconds. $mem MiB allocated." "Parsing file $i/$count: {$uri}"
); );
try {
$document = yield $this->documentLoader->load($uri);
if (!$document->isVendored()) {
$this->client->textDocument->publishDiagnostics($uri, $document->getDiagnostics());
}
} catch (ContentTooLargeException $e) {
$this->client->window->logMessage(
MessageType::INFO,
"Ignoring file {$uri} because it exceeds size limit of {$e->limit} bytes ({$e->size})"
);
} catch (Exception $e) {
$this->client->window->logMessage(
MessageType::ERROR,
"Error parsing file {$uri}: " . (string)$e
);
}
}
$duration = (int)(microtime(true) - $startTime);
$mem = (int)(memory_get_usage(true) / (1024 * 1024));
$this->client->window->logMessage(
MessageType::INFO,
"All $count PHP files parsed in $duration seconds. $mem MiB allocated."
);
}
}); });
} }
} }

View File

@ -73,7 +73,8 @@ class LanguageServerTest extends TestCase
$rootPath = realpath(__DIR__ . '/../fixtures'); $rootPath = realpath(__DIR__ . '/../fixtures');
$input = new MockProtocolStream; $input = new MockProtocolStream;
$output = new MockProtocolStream; $output = new MockProtocolStream;
$output->on('message', function (Message $msg) use ($promise, $input, $rootPath, &$filesCalled, &$contentCalled) { $run = 1;
$output->on('message', function (Message $msg) use ($promise, $input, $rootPath, &$filesCalled, &$contentCalled, &$run) {
if ($msg->body->method === 'textDocument/xcontent') { if ($msg->body->method === 'textDocument/xcontent') {
// Document content requested // Document content requested
$contentCalled = true; $contentCalled = true;
@ -100,8 +101,11 @@ class LanguageServerTest extends TestCase
$promise->reject(new Exception($msg->body->params->message)); $promise->reject(new Exception($msg->body->params->message));
} }
} else if (strpos($msg->body->params->message, 'All 25 PHP files parsed') !== false) { } else if (strpos($msg->body->params->message, 'All 25 PHP files parsed') !== false) {
// Indexing finished if ($run === 1) {
$promise->fulfill(); $run++;
} else {
$promise->fulfill();
}
} }
} }
}); });