-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathproxy
executable file
·61 lines (51 loc) · 1.62 KB
/
proxy
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
#!/usr/bin/env php
<?php
use DTL\Invoke\Invoke;
use Phpactor\LanguageServerProtocol\ClientCapabilities;
use Phpactor\LanguageServerProtocol\InitializeParams;
use Phpactor\LanguageServer\Core\Rpc\NotificationMessage;
use Phpactor\LanguageServer\Core\Rpc\RequestMessage;
use Phpactor\LanguageServer\Core\Rpc\ResponseMessage;
use Phpactor\LanguageServer\Core\Server\Transmitter\MessageFormatter;
require __DIR__ . '/../vendor/autoload.php';
if (!isset($argv[1])) {
error('Must pass the requet type, one of "request", "notification" or "response"');
exit(1);
}
$type = $argv[1];
$payload = fgets(STDIN);
$payload = json_decode($payload, true);
if (null === $payload) {
error('Could not decode JSON');
exit(1);
}
try {
switch ($type) {
case 'request':
$message = Invoke::new(RequestMessage::class, $payload);
break;
case 'response':
$message = Invoke::new(ResponseMessage::class, $payload);
break;
case 'notification':
$message = Invoke::new(NotificationMessage::class, $payload);
break;
default:
error(sprintf('Unknown message type, must be "request", "response" or "notifiaction", got "%s"', $type));
exit(1);
}
} catch (\Exception $e) {
error($e->getMessage());
exit(1);
}
$formatter = new MessageFormatter();
fwrite(STDOUT, $formatter->write(new RequestMessage(
1,
'initialize',
json_decode(json_encode(new InitializeParams(new ClientCapabilities())), true)
)));
fwrite(STDOUT, $formatter->write($message));
function error(string $message): void
{
echo $message . "\n";
}