1
0
Fork 0

Array only for xglob $patterns

pull/136/head
Felix Becker 2016-11-06 23:54:52 +01:00
parent 232f5c329d
commit d833196757
2 changed files with 16 additions and 10 deletions

View File

@ -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 * @param string[] $patterns Glob patterns
* @return Promise <TextDocumentIdentifier[]> Array of documents that match the glob pattern * @return Promise <TextDocumentIdentifier[]> 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); return $this->mapper->mapArray($textDocuments, [], TextDocumentIdentifier::class);
}); });
} }

View File

@ -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->globWorkspace(['**/*.php']);
$count = count($textDocuments); $count = count($textDocuments);
$startTime = microtime(true); $startTime = microtime(true);
@ -207,23 +207,26 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
* Returns all files matching a glob pattern. * Returns all files matching a glob pattern.
* If the client does not support workspace/xglob, it falls back to globbing the file system directly. * 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 <TextDocumentIdentifier[]> * @return Promise <TextDocumentIdentifier[]>
*/ */
private function globWorkspace(string $pattern): Promise private function globWorkspace(array $patterns): Promise
{ {
if ($this->clientCapabilities->xglobProvider) { if ($this->clientCapabilities->xglobProvider) {
// Use xglob request // Use xglob request
return $this->client->workspace->xglob($pattern); return $this->client->workspace->xglob($patterns);
} else { } else {
// Use the file system // Use the file system
return coroutine(function () use ($pattern) {
$textDocuments = []; $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($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;
}); });
} }