From 0a0cd22a0a13b13c06423d138f4a89b6b109ed27 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Wed, 19 Oct 2016 21:43:19 +0200 Subject: [PATCH] Handle case where $rootPath is null --- src/LanguageServer.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/LanguageServer.php b/src/LanguageServer.php index 86fdcb5..15741d1 100644 --- a/src/LanguageServer.php +++ b/src/LanguageServer.php @@ -101,11 +101,10 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher { $this->rootPath = $rootPath; - $this->restoreCache(); - // start building project index - if ($rootPath) { - $this->indexProject($rootPath); + if ($rootPath !== null) { + $this->restoreCache(); + $this->indexProject(); } $serverCapabilities = new ServerCapabilities(); @@ -136,7 +135,9 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher */ public function shutdown() { - $this->saveCache(); + if ($this->rootPath !== null) { + $this->saveCache(); + } } /** @@ -152,23 +153,23 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher /** * Parses workspace files, one at a time. * - * @param string $rootPath The rootPath of the workspace. * @return void */ - private function indexProject(string $rootPath) + private function indexProject() { - $fileList = findFilesRecursive($rootPath, '/^.+\.php$/i'); + $fileList = findFilesRecursive($this->rootPath, '/^.+\.php$/i'); $numTotalFiles = count($fileList); $startTime = microtime(true); $fileNum = 0; - $processFile = function() use (&$fileList, &$fileNum, &$processFile, $rootPath, $numTotalFiles, $startTime) { + $processFile = function() use (&$fileList, &$fileNum, &$processFile, $numTotalFiles, $startTime) { if ($fileNum < $numTotalFiles) { $file = $fileList[$fileNum]; $uri = pathToUri($file); $fileNum++; - $shortName = substr($file, strlen($rootPath) + 1); + $shortName = substr($file, strlen($this->rootPath) + 1); + $this->client->window->logMessage(MessageType::INFO, "Parsing file $fileNum/$numTotalFiles: $shortName."); if (filesize($file) > 500000) { $this->client->window->logMessage(MessageType::INFO, "Not parsing $shortName because it exceeds size limit of 0.5MB");