1
0
Fork 0

Merge branch 'master' into completion

pull/165/head
Felix Becker 2016-11-30 22:14:19 +01:00 committed by GitHub
commit 90297f2ec0
4 changed files with 22 additions and 4 deletions

View File

@ -68,10 +68,12 @@ if (!empty($options['tcp'])) {
exit(1); exit(1);
} else if ($pid === 0) { } else if ($pid === 0) {
// Child process // Child process
$ls = new LanguageServer( $reader = new ProtocolStreamReader($socket);
new ProtocolStreamReader($socket), $writer = new ProtocolStreamWriter($socket);
new ProtocolStreamWriter($socket) $reader->on('close', function () {
); fwrite(STDOUT, "Connection closed\n");
});
$ls = new LanguageServer($reader, $writer);
Loop\run(); Loop\run();
// Just for safety // Just for safety
exit(0); exit(0);

View File

@ -66,6 +66,10 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
{ {
parent::__construct($this, '/'); parent::__construct($this, '/');
$this->protocolReader = $reader; $this->protocolReader = $reader;
$this->protocolReader->on('close', function () {
$this->shutdown();
$this->exit();
});
$this->protocolReader->on('message', function (Message $msg) { $this->protocolReader->on('message', function (Message $msg) {
coroutine(function () use ($msg) { coroutine(function () use ($msg) {
// Ignore responses, this is the handler for requests and notifications // Ignore responses, this is the handler for requests and notifications

View File

@ -8,6 +8,8 @@ use Sabre\Event\EmitterInterface;
/** /**
* Must emit a "message" event with a Protocol\Message object as parameter * Must emit a "message" event with a Protocol\Message object as parameter
* when a message comes in * when a message comes in
*
* Must emit a "close" event when the stream closes
*/ */
interface ProtocolReader extends EmitterInterface interface ProtocolReader extends EmitterInterface
{ {

View File

@ -25,7 +25,17 @@ class ProtocolStreamReader extends Emitter implements ProtocolReader
{ {
$this->input = $input; $this->input = $input;
$this->on('close', function () {
Loop\removeReadStream($this->input);
});
Loop\addReadStream($this->input, function () { 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 !== '') { while (($c = fgetc($this->input)) !== false && $c !== '') {
$this->buffer .= $c; $this->buffer .= $c;
switch ($this->parsingMode) { switch ($this->parsingMode) {