Merge branch 'master' into completion
commit
90297f2ec0
|
@ -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);
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue