1
0
Fork 0

Merge branch 'master' into no-fs

pull/136/head
Felix Becker 2016-11-07 12:26:32 +01:00
commit 745fec4d92
4 changed files with 31 additions and 6 deletions

View File

@ -199,7 +199,10 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
$duration = (int)(microtime(true) - $startTime); $duration = (int)(microtime(true) - $startTime);
$mem = (int)(memory_get_usage(true) / (1024 * 1024)); $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->client->window->logMessage(
MessageType::INFO,
"All $count PHP files parsed in $duration seconds. $mem MiB allocated."
);
}); });
} }
@ -217,7 +220,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
return $this->client->workspace->xglob($patterns); return $this->client->workspace->xglob($patterns);
} else { } else {
// Use the file system // Use the file system
$textDocuments = []; $textDocuments = [];
return Promise\all(array_map(function ($pattern) use (&$textDocuments) { return Promise\all(array_map(function ($pattern) use (&$textDocuments) {
return coroutine(function () use ($pattern, &$textDocuments) { return coroutine(function () use ($pattern, &$textDocuments) {
$pattern = Path::makeAbsolute($pattern, $this->rootPath); $pattern = Path::makeAbsolute($pattern, $this->rootPath);
@ -226,7 +229,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
yield timeout(); yield timeout();
} }
}); });
}, $patterns))->then(function () use ($textDocuments) { }, $patterns))->then(function () use (&$textDocuments) {
return $textDocuments; return $textDocuments;
}); });
} }

View File

@ -22,7 +22,7 @@ function pathToUri(string $filepath): string
if (substr($first, -1) !== ':') { if (substr($first, -1) !== ':') {
$first = urlencode($first); $first = urlencode($first);
} }
$parts = array_map('urlencode', $parts); $parts = array_map('rawurlencode', $parts);
array_unshift($parts, $first); array_unshift($parts, $first);
$filepath = implode('/', $parts); $filepath = implode('/', $parts);
return 'file:///' . $filepath; return 'file:///' . $filepath;

View File

@ -5,8 +5,10 @@ namespace LanguageServer\Tests;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use LanguageServer\LanguageServer; use LanguageServer\LanguageServer;
use LanguageServer\Protocol\{Message, ClientCapabilities, TextDocumentSyncKind}; use LanguageServer\Protocol\{Message, ClientCapabilities, TextDocumentSyncKind, MessageType};
use AdvancedJsonRpc; use AdvancedJsonRpc;
use Sabre\Event\Promise;
use function LanguageServer\pathToUri;
class LanguageServerTest extends TestCase class LanguageServerTest extends TestCase
{ {
@ -46,4 +48,24 @@ class LanguageServerTest extends TestCase
] ]
], $msg->body->result); ], $msg->body->result);
} }
public function testIndexing()
{
$promise = new Promise;
$input = new MockProtocolStream;
$output = new MockProtocolStream;
$output->on('message', function (Message $msg) use ($promise) {
if ($msg->body->method === 'window/logMessage') {
if ($msg->body->params->type === MessageType::ERROR) {
$promise->reject();
} else if (strpos($msg->body->params->message, 'All 10 PHP files parsed') !== false) {
$promise->fulfill();
}
}
});
$server = new LanguageServer($input, $output);
$capabilities = new ClientCapabilities;
$server->initialize(getmypid(), $capabilities, realpath(__DIR__ . '/../fixtures'));
$promise->wait();
}
} }

View File

@ -25,7 +25,7 @@ class FileUriTest extends TestCase
// special chars are escaped // special chars are escaped
$uri = pathToUri('c:/path/to/file/dürüm döner.php'); $uri = pathToUri('c:/path/to/file/dürüm döner.php');
$this->assertEquals('file:///c:/path/to/file/d%C3%BCr%C3%BCm+d%C3%B6ner.php', $uri); $this->assertEquals('file:///c:/path/to/file/d%C3%BCr%C3%BCm%20d%C3%B6ner.php', $uri);
//backslashes are transformed //backslashes are transformed
$uri = pathToUri('c:\\foo\\bar.baz'); $uri = pathToUri('c:\\foo\\bar.baz');