Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove caching for now #118

Merged
merged 1 commit into from
Oct 26, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 0 additions & 59 deletions src/LanguageServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public function initialize(int $processId, ClientCapabilities $capabilities, str

// start building project index
if ($rootPath !== null) {
$this->restoreCache();
$this->indexProject();
}

Expand Down Expand Up @@ -135,9 +134,6 @@ public function initialize(int $processId, ClientCapabilities $capabilities, str
*/
public function shutdown()
{
if ($this->rootPath !== null) {
$this->saveCache();
}
}

/**
Expand Down Expand Up @@ -181,69 +177,14 @@ private function indexProject()
}
}

if ($fileNum % 1000 === 0) {
$this->saveCache();
}

Loop\setTimeout($processFile, 0);
} else {
$duration = (int)(microtime(true) - $startTime);
$mem = (int)(memory_get_usage(true) / (1024 * 1024));
$this->client->window->logMessage(MessageType::INFO, "All PHP files parsed in $duration seconds. $mem MiB allocated.");
$this->saveCache();
}
};

Loop\setTimeout($processFile, 0);
}

/**
* Restores the definition and reference index from the .phpls cache directory, if available
*
* @return void
*/
public function restoreCache()
{
$cacheDir = $this->rootPath . '/.phpls';
if (is_dir($cacheDir)) {
if (file_exists($cacheDir . '/symbols')) {
$symbols = unserialize(file_get_contents($cacheDir . '/symbols'));
$count = count($symbols);
$this->project->setSymbols($symbols);
$this->client->window->logMessage(MessageType::INFO, "Restoring $count symbols");
}
if (file_exists($cacheDir . '/references')) {
$references = unserialize(file_get_contents($cacheDir . '/references'));
$count = array_sum(array_map('count', $references));
$this->project->setReferenceUris($references);
$this->client->window->logMessage(MessageType::INFO, "Restoring $count references");
}
} else {
$this->client->window->logMessage(MessageType::INFO, 'No cache found');
}
}

/**
* Saves the definition and reference index to the .phpls cache directory
*
* @return void
*/
public function saveCache()
{
// Cache definitions, references
$cacheDir = $this->rootPath . '/.phpls';
if (!is_dir($cacheDir)) {
mkdir($cacheDir);
}

$symbols = $this->project->getSymbols();
$count = count($symbols);
$this->client->window->logMessage(MessageType::INFO, "Saving $count symbols to cache");
file_put_contents($cacheDir . "/symbols", serialize($symbols));

$references = $this->project->getReferenceUris();
$count = array_sum(array_map('count', $references));
$this->client->window->logMessage(MessageType::INFO, "Saving $count references to cache");
file_put_contents($cacheDir . "/references", serialize($references));
}
}