diff --git a/src/LanguageServer.php b/src/LanguageServer.php index 2a5a716..f1706e9 100644 --- a/src/LanguageServer.php +++ b/src/LanguageServer.php @@ -238,42 +238,43 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher $startTime = microtime(true); - // Parse PHP files - foreach ($uris as $i => $uri) { - 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()); + foreach (['Collecting definitions and static references', 'Collecting dynamic references'] as $run) { + $this->client->window->logMessage(MessageType::INFO, $run); + foreach ($uris as $i => $uri) { + if ($this->documentLoader->isOpen($uri)) { + continue; } - } 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." - ); + // 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); + $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." + ); + } }); } } diff --git a/tests/LanguageServerTest.php b/tests/LanguageServerTest.php index d9f0d81..6f8e705 100644 --- a/tests/LanguageServerTest.php +++ b/tests/LanguageServerTest.php @@ -73,7 +73,8 @@ class LanguageServerTest extends TestCase $rootPath = realpath(__DIR__ . '/../fixtures'); $input = 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') { // Document content requested $contentCalled = true; @@ -100,8 +101,11 @@ class LanguageServerTest extends TestCase $promise->reject(new Exception($msg->body->params->message)); } } else if (strpos($msg->body->params->message, 'All 25 PHP files parsed') !== false) { - // Indexing finished - $promise->fulfill(); + if ($run === 1) { + $run++; + } else { + $promise->fulfill(); + } } } });