1
0
Fork 0

Integrate latest protocol changes

* workspace/glob becomes workspace/files
* return type of textDocument/files is now TextDocumentItem
pull/136/head
Felix Becker 2016-11-12 10:15:37 +01:00
parent 898349b69f
commit cdb2c46f68
4 changed files with 22 additions and 47 deletions

View File

@ -4,7 +4,7 @@ declare(strict_types = 1);
namespace LanguageServer\Client;
use LanguageServer\ClientHandler;
use LanguageServer\Protocol\{Message, Content, TextDocumentIdentifier};
use LanguageServer\Protocol\{Message, TextDocumentItem, TextDocumentIdentifier};
use Sabre\Event\Promise;
use JsonMapper;
@ -57,7 +57,7 @@ class TextDocument
'textDocument/xcontent',
['textDocument' => $textDocument]
)->then(function ($result) {
return $this->mapper->map($result, new Content);
return $this->mapper->map($result, new TextDocumentItem);
});
}
}

View File

@ -173,7 +173,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
private function indexProject(): Promise
{
return coroutine(function () {
$textDocuments = yield $this->globWorkspace(['**/*.php']);
$textDocuments = yield $this->findPhpFiles();
$count = count($textDocuments);
$startTime = microtime(true);
@ -207,31 +207,27 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
}
/**
* Returns all files matching a glob pattern.
* If the client does not support workspace/xglob, it falls back to globbing the file system directly.
* Returns all PHP files in the workspace.
* If the client does not support workspace/files, it falls back to searching the file system directly.
*
* @param string $patterns
* @return Promise <TextDocumentIdentifier[]>
*/
private function globWorkspace(array $patterns): Promise
private function findPhpFiles(): Promise
{
if ($this->clientCapabilities->xglobProvider) {
// Use xglob request
return $this->client->workspace->xglob($patterns);
return coroutine(function () {
if ($this->clientCapabilities->xfilesProvider) {
// Use xfiles request
return yield $this->client->workspace->xfiles($patterns);
} else {
// Use the file system
$textDocuments = [];
return Promise\all(array_map(function ($pattern) use (&$textDocuments) {
return coroutine(function () use ($pattern, &$textDocuments) {
$pattern = Path::makeAbsolute($pattern, $this->rootPath);
$pattern = Path::makeAbsolute('**/*.php', $this->rootPath);
foreach (new GlobIterator($pattern) as $path) {
$textDocuments[] = new TextDocumentIdentifier(pathToUri($path));
yield timeout();
}
});
}, $patterns))->then(function () use (&$textDocuments) {
return $textDocuments;
});
}
});
}
}

View File

@ -5,11 +5,11 @@ namespace LanguageServer\Protocol;
class ClientCapabilities
{
/**
* The client supports workspace/xglob requests
* The client supports workspace/xfiles requests
*
* @var bool|null
*/
public $xglobProvider;
public $xfilesProvider;
/**
* The client supports textDocument/xcontent requests

View File

@ -1,21 +0,0 @@
<?php
namespace LanguageServer\Protocol;
class Content
{
/**
* The content of the text document
*
* @var string
*/
public $text;
/**
* @param string $text The content of the text document
*/
public function __construct(string $text = null)
{
$this->text = $text;
}
}