diff --git a/src/Client/Workspace.php b/src/Client/Workspace.php index d2bf239..8e277e5 100644 --- a/src/Client/Workspace.php +++ b/src/Client/Workspace.php @@ -30,14 +30,17 @@ class Workspace } /** - * Returns a list of all files in the workspace that match a glob pattern + * Returns a list of all files in the workspace that match any of the given glob patterns * - * @param string $pattern A glob pattern - * @return Promise Array of documents that match the glob pattern + * @param string[] $patterns Glob patterns + * @return Promise Array of documents that match the glob patterns */ - public function xglob(string $pattern): Promise + public function xglob(array $patterns): Promise { - return $this->handler->request('workspace/xglob', ['pattern' => $pattern])->then(function ($textDocuments) { + return $this->handler->request( + 'workspace/xglob', + ['patterns' => $patterns] + )->then(function (array $textDocuments) { return $this->mapper->mapArray($textDocuments, [], TextDocumentIdentifier::class); }); } diff --git a/src/LanguageServer.php b/src/LanguageServer.php index a4e88fb..d652fb0 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->globWorkspace(['**/*.php']); $count = count($textDocuments); $startTime = microtime(true); @@ -207,23 +207,26 @@ 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. * - * @param string $pattern + * @param string $patterns * @return Promise */ - private function globWorkspace(string $pattern): Promise + private function globWorkspace(array $patterns): Promise { if ($this->clientCapabilities->xglobProvider) { // Use xglob request - return $this->client->workspace->xglob($pattern); + return $this->client->workspace->xglob($patterns); } else { // Use the file system - return coroutine(function () use ($pattern) { $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 $textDocuments; }); }