Merge branch 'master' into completion
commit
90297f2ec0
|
@ -68,10 +68,12 @@ if (!empty($options['tcp'])) {
|
|||
exit(1);
|
||||
} else if ($pid === 0) {
|
||||
// Child process
|
||||
$ls = new LanguageServer(
|
||||
new ProtocolStreamReader($socket),
|
||||
new ProtocolStreamWriter($socket)
|
||||
);
|
||||
$reader = new ProtocolStreamReader($socket);
|
||||
$writer = new ProtocolStreamWriter($socket);
|
||||
$reader->on('close', function () {
|
||||
fwrite(STDOUT, "Connection closed\n");
|
||||
});
|
||||
$ls = new LanguageServer($reader, $writer);
|
||||
Loop\run();
|
||||
// Just for safety
|
||||
exit(0);
|
||||
|
|
|
@ -66,6 +66,10 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
|
|||
{
|
||||
parent::__construct($this, '/');
|
||||
$this->protocolReader = $reader;
|
||||
$this->protocolReader->on('close', function () {
|
||||
$this->shutdown();
|
||||
$this->exit();
|
||||
});
|
||||
$this->protocolReader->on('message', function (Message $msg) {
|
||||
coroutine(function () use ($msg) {
|
||||
// Ignore responses, this is the handler for requests and notifications
|
||||
|
|
|
@ -8,6 +8,8 @@ use Sabre\Event\EmitterInterface;
|
|||
/**
|
||||
* Must emit a "message" event with a Protocol\Message object as parameter
|
||||
* when a message comes in
|
||||
*
|
||||
* Must emit a "close" event when the stream closes
|
||||
*/
|
||||
interface ProtocolReader extends EmitterInterface
|
||||
{
|
||||
|
|
|
@ -25,7 +25,17 @@ class ProtocolStreamReader extends Emitter implements ProtocolReader
|
|||
{
|
||||
$this->input = $input;
|
||||
|
||||
$this->on('close', function () {
|
||||
Loop\removeReadStream($this->input);
|
||||
});
|
||||
|
||||
Loop\addReadStream($this->input, function () {
|
||||
if (feof($this->input)) {
|
||||
// If stream_select reported a status change for this stream,
|
||||
// but the stream is EOF, it means it was closed.
|
||||
$this->emit('close');
|
||||
return;
|
||||
}
|
||||
while (($c = fgetc($this->input)) !== false && $c !== '') {
|
||||
$this->buffer .= $c;
|
||||
switch ($this->parsingMode) {
|
||||
|
|
Loading…
Reference in New Issue