From cdb2c46f6896c76502a819da1f73aea8b1963bc8 Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Sat, 12 Nov 2016 10:15:37 +0100 Subject: [PATCH] Integrate latest protocol changes * workspace/glob becomes workspace/files * return type of textDocument/files is now TextDocumentItem --- src/Client/TextDocument.php | 4 +-- src/LanguageServer.php | 40 +++++++++++++---------------- src/Protocol/ClientCapabilities.php | 4 +-- src/Protocol/Content.php | 21 --------------- 4 files changed, 22 insertions(+), 47 deletions(-) delete mode 100644 src/Protocol/Content.php diff --git a/src/Client/TextDocument.php b/src/Client/TextDocument.php index 6cf09cd..4f35656 100644 --- a/src/Client/TextDocument.php +++ b/src/Client/TextDocument.php @@ -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); }); } } diff --git a/src/LanguageServer.php b/src/LanguageServer.php index 0af06aa..a6789b9 100644 --- a/src/LanguageServer.php +++ b/src/LanguageServer.php @@ -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 */ - private function globWorkspace(array $patterns): Promise + private function findPhpFiles(): Promise { - if ($this->clientCapabilities->xglobProvider) { - // Use xglob request - return $this->client->workspace->xglob($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); - foreach (new GlobIterator($pattern) as $path) { - $textDocuments[] = new TextDocumentIdentifier(pathToUri($path)); - yield timeout(); - } - }); - }, $patterns))->then(function () use (&$textDocuments) { + return coroutine(function () { + if ($this->clientCapabilities->xfilesProvider) { + // Use xfiles request + return yield $this->client->workspace->xfiles($patterns); + } else { + // Use the file system + $textDocuments = []; + $pattern = Path::makeAbsolute('**/*.php', $this->rootPath); + foreach (new GlobIterator($pattern) as $path) { + $textDocuments[] = new TextDocumentIdentifier(pathToUri($path)); + yield timeout(); + } return $textDocuments; - }); - } + } + }); } } diff --git a/src/Protocol/ClientCapabilities.php b/src/Protocol/ClientCapabilities.php index f72a681..42137e9 100644 --- a/src/Protocol/ClientCapabilities.php +++ b/src/Protocol/ClientCapabilities.php @@ -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 diff --git a/src/Protocol/Content.php b/src/Protocol/Content.php deleted file mode 100644 index c1b9381..0000000 --- a/src/Protocol/Content.php +++ /dev/null @@ -1,21 +0,0 @@ -text = $text; - } -}