1
0
Fork 0
pull/367/merge
John S Long 2017-06-10 09:05:08 +00:00 committed by GitHub
commit dc469f59a9
6 changed files with 90 additions and 6 deletions

6
fixtures/composer.json Normal file
View File

@ -0,0 +1,6 @@
{
"require": {
"example/example-version": "1.0.7",
"example/example-reference": "dev-master"
}
}

55
fixtures/composer.lock generated Normal file
View File

@ -0,0 +1,55 @@
{
"_readme": [
"This is a mock lock file for composer"
],
"content-hash": "3da868eb11c9a94f957057f73d2936ef",
"packages": [
{
"name": "example/example-version",
"version": "1.0.7",
"source": {
"type": "git",
"url": "https://example.com",
"reference": "b17e6153cb7f33c7e44eb59578dc12eee5dc8e12"
},
"require": {},
"require-dev": {},
"suggest": {},
"type": "library",
"extra": {},
"autoload": {},
"license": [],
"authors": [],
"description": "",
"keywords": [],
"time": "2017-03-06T11:59:08+00:00"
},
{
"name": "example/example-reference",
"version": "1.0.7",
"source": {
"type": "git",
"url": "https://example.com",
"reference": "b17e6153cb7f33c7e44eb59578dc12eee5dc8e12"
},
"require": {},
"require-dev": {},
"suggest": {},
"type": "library",
"extra": {},
"autoload": {},
"license": [],
"authors": [],
"description": "",
"keywords": [],
"time": "2017-03-06T11:59:08+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "dev",
"prefer-stable": true,
"prefer-lowest": false,
"platform": {},
"platform-dev": []
}

View File

@ -0,0 +1 @@
<?php

View File

@ -0,0 +1,3 @@
<?php

View File

@ -150,15 +150,26 @@ class Indexer
$cacheKey = null;
$index = null;
foreach (array_merge($this->composerLock->packages, $this->composerLock->{'packages-dev'}) as $package) {
// Check if package name matches and version is absolute
// Dynamic constraints are not cached, because they can change every time
if ($package->name !== $packageName) {
continue;
}
// Check if package can be cached.
$packageVersion = ltrim($package->version, 'v');
if ($package->name === $packageName && strpos($packageVersion, 'dev') === false) {
// If package is anchored to a version
if (strpos($packageVersion, 'dev') === false) {
$packageKey = $packageName . ':' . $packageVersion;
$cacheKey = self::CACHE_VERSION . ':' . $packageKey;
// Check cache
$index = yield $this->cache->get($cacheKey);
break;
// If package is checked out
} else if (isset($package->source->reference)) {
$packageKey = $packageName . ':' . $package->source->reference;
$cacheKey = self::CACHE_VERSION . ':' . $packageKey;
// Check cache
$index = yield $this->cache->get($cacheKey);
break;
}
}
if ($index !== null) {

View File

@ -53,12 +53,18 @@ class LanguageServerTest extends TestCase
$promise = new Promise;
$input = new MockProtocolStream;
$output = new MockProtocolStream;
$output->on('message', function (Message $msg) use ($promise) {
$cacheVersionCalled = false;
$cacheReferenceCalled = false;
$output->on('message', function (Message $msg) use ($promise, &$cacheVersionCalled, &$cacheReferenceCalled) {
if ($msg->body->method === 'window/logMessage' && $promise->state === Promise::PENDING) {
if ($msg->body->params->type === MessageType::ERROR) {
$promise->reject(new Exception($msg->body->params->message));
} else if (strpos($msg->body->params->message, 'All 27 PHP files parsed') !== false) {
} else if (preg_match('/All [0-9]+ PHP files parsed/', $msg->body->params->message)) {
$promise->fulfill();
} else if (preg_match('#(Storing|Restored) example/example-version:.* (in|from) cache#', $msg->body->params->message)) {
$cacheVersionCalled = true;
} else if (preg_match('#(Storing|Restored) example/example-reference:.* (in|from) cache#', $msg->body->params->message)) {
$cacheReferenceCalled = true;
}
}
});
@ -66,6 +72,8 @@ class LanguageServerTest extends TestCase
$capabilities = new ClientCapabilities;
$server->initialize($capabilities, realpath(__DIR__ . '/../fixtures'), getmypid());
$promise->wait();
$this->assertTrue($cacheVersionCalled);
$this->assertTrue($cacheReferenceCalled);
}
public function testIndexingWithFilesAndContentRequests()
@ -103,7 +111,7 @@ class LanguageServerTest extends TestCase
if ($promise->state === Promise::PENDING) {
$promise->reject(new Exception($msg->body->params->message));
}
} else if (strpos($msg->body->params->message, 'All 27 PHP files parsed') !== false) {
} else if (preg_match('/All [0-9]+ PHP files parsed/', $msg->body->params->message)) {
$promise->fulfill();
}
}