Integrate latest protocol changes
* workspace/glob becomes workspace/files * return type of textDocument/files is now TextDocumentItempull/136/head
parent
898349b69f
commit
cdb2c46f68
|
@ -4,7 +4,7 @@ declare(strict_types = 1);
|
||||||
namespace LanguageServer\Client;
|
namespace LanguageServer\Client;
|
||||||
|
|
||||||
use LanguageServer\ClientHandler;
|
use LanguageServer\ClientHandler;
|
||||||
use LanguageServer\Protocol\{Message, Content, TextDocumentIdentifier};
|
use LanguageServer\Protocol\{Message, TextDocumentItem, TextDocumentIdentifier};
|
||||||
use Sabre\Event\Promise;
|
use Sabre\Event\Promise;
|
||||||
use JsonMapper;
|
use JsonMapper;
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ class TextDocument
|
||||||
'textDocument/xcontent',
|
'textDocument/xcontent',
|
||||||
['textDocument' => $textDocument]
|
['textDocument' => $textDocument]
|
||||||
)->then(function ($result) {
|
)->then(function ($result) {
|
||||||
return $this->mapper->map($result, new Content);
|
return $this->mapper->map($result, new TextDocumentItem);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,7 +173,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
||||||
private function indexProject(): Promise
|
private function indexProject(): Promise
|
||||||
{
|
{
|
||||||
return coroutine(function () {
|
return coroutine(function () {
|
||||||
$textDocuments = yield $this->globWorkspace(['**/*.php']);
|
$textDocuments = yield $this->findPhpFiles();
|
||||||
$count = count($textDocuments);
|
$count = count($textDocuments);
|
||||||
|
|
||||||
$startTime = microtime(true);
|
$startTime = microtime(true);
|
||||||
|
@ -207,31 +207,27 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all files matching a glob pattern.
|
* Returns all PHP files in the workspace.
|
||||||
* If the client does not support workspace/xglob, it falls back to globbing the file system directly.
|
* If the client does not support workspace/files, it falls back to searching the file system directly.
|
||||||
*
|
*
|
||||||
* @param string $patterns
|
|
||||||
* @return Promise <TextDocumentIdentifier[]>
|
* @return Promise <TextDocumentIdentifier[]>
|
||||||
*/
|
*/
|
||||||
private function globWorkspace(array $patterns): Promise
|
private function findPhpFiles(): Promise
|
||||||
{
|
{
|
||||||
if ($this->clientCapabilities->xglobProvider) {
|
return coroutine(function () {
|
||||||
// Use xglob request
|
if ($this->clientCapabilities->xfilesProvider) {
|
||||||
return $this->client->workspace->xglob($patterns);
|
// Use xfiles request
|
||||||
|
return yield $this->client->workspace->xfiles($patterns);
|
||||||
} else {
|
} else {
|
||||||
// Use the file system
|
// Use the file system
|
||||||
$textDocuments = [];
|
$textDocuments = [];
|
||||||
return Promise\all(array_map(function ($pattern) use (&$textDocuments) {
|
$pattern = Path::makeAbsolute('**/*.php', $this->rootPath);
|
||||||
return coroutine(function () use ($pattern, &$textDocuments) {
|
|
||||||
$pattern = Path::makeAbsolute($pattern, $this->rootPath);
|
|
||||||
foreach (new GlobIterator($pattern) as $path) {
|
foreach (new GlobIterator($pattern) as $path) {
|
||||||
$textDocuments[] = new TextDocumentIdentifier(pathToUri($path));
|
$textDocuments[] = new TextDocumentIdentifier(pathToUri($path));
|
||||||
yield timeout();
|
yield timeout();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}, $patterns))->then(function () use (&$textDocuments) {
|
|
||||||
return $textDocuments;
|
return $textDocuments;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,11 @@ namespace LanguageServer\Protocol;
|
||||||
class ClientCapabilities
|
class ClientCapabilities
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The client supports workspace/xglob requests
|
* The client supports workspace/xfiles requests
|
||||||
*
|
*
|
||||||
* @var bool|null
|
* @var bool|null
|
||||||
*/
|
*/
|
||||||
public $xglobProvider;
|
public $xfilesProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The client supports textDocument/xcontent requests
|
* The client supports textDocument/xcontent requests
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue