forked from phpactor/language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAggregateCodeActionProvider.php
More file actions
66 lines (56 loc) · 1.7 KB
/
AggregateCodeActionProvider.php
File metadata and controls
66 lines (56 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace Phpactor\LanguageServer\Core\CodeAction;
use Amp\CancellationToken;
use Amp\Promise;
use Phpactor\LanguageServerProtocol\Range;
use Phpactor\LanguageServerProtocol\TextDocumentItem;
use function Amp\call;
use function Amp\delay;
class AggregateCodeActionProvider implements CodeActionProvider
{
/**
* @var CodeActionProvider[]
*/
private array $providers;
public function __construct(CodeActionProvider ...$providers)
{
$this->providers = $providers;
}
/**
* {@inheritDoc}
*/
public function provideActionsFor(TextDocumentItem $textDocument, Range $range, CancellationToken $cancel): Promise
{
return call(function () use ($textDocument, $range, $cancel) {
$actions = [];
foreach ($this->providers as $provider) {
$actions = array_merge($actions, yield $provider->provideActionsFor($textDocument, $range, $cancel));
yield delay(0);
$cancel->throwIfRequested();
}
return $actions;
});
}
/**
* {@inheritDoc}
*/
public function kinds(): array
{
return array_values(
array_reduce(
$this->providers,
function (array $kinds, CodeActionProvider $provider): array {
return array_merge(
$kinds,
(array)array_combine($provider->kinds(), $provider->kinds())
);
},
[]
)
);
}
public function describe(): string
{
return sprintf('aggregate code action proivder with %s providers', count($this->providers));
}
}