forked from phpactor/language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestResponseWatcher.php
More file actions
48 lines (41 loc) · 1.14 KB
/
TestResponseWatcher.php
File metadata and controls
48 lines (41 loc) · 1.14 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
<?php
namespace Phpactor\LanguageServer\Core\Server\ResponseWatcher;
use Amp\Promise;
use Phpactor\LanguageServer\Core\Rpc\ResponseMessage;
use Phpactor\LanguageServer\Core\Server\ResponseWatcher;
use RuntimeException;
final class TestResponseWatcher implements ResponseWatcher
{
/**
* @var array
*/
private array $requestIds = [];
public function __construct(private ResponseWatcher $innerWatcher = new DeferredResponseWatcher())
{
}
public function handle(ResponseMessage $response): void
{
$this->innerWatcher->handle($response);
}
/**
* @param mixed $result
*/
public function resolveLastResponse($result): void
{
$id = array_shift($this->requestIds);
if (null === $id) {
throw new RuntimeException(
'No responses left to handle'
);
}
$this->handle(new ResponseMessage($id, $result));
}
/**
* {@inheritDoc}
*/
public function waitForResponse(int|string $requestId): Promise
{
$this->requestIds[] = $requestId;
return $this->innerWatcher->waitForResponse($requestId);
}
}