1
0
Fork 0

Fix crash

pull/89/merge
Felix Becker 2016-10-20 03:36:03 +02:00
parent 953a8023b7
commit 8e36e59e9a
1 changed files with 10 additions and 5 deletions

View File

@ -49,21 +49,26 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher
parent::__construct($this, '/'); parent::__construct($this, '/');
$this->protocolReader = $reader; $this->protocolReader = $reader;
$this->protocolReader->onMessage(function (Message $msg) { $this->protocolReader->onMessage(function (Message $msg) {
$result = null;
$error = null;
try { try {
// Invoke the method handler to get a result // Invoke the method handler to get a result
$result = $this->dispatch($msg->body); $result = $this->dispatch($msg->body);
$responseBody = new AdvancedJsonRpc\SuccessResponse($msg->body->id, $result); } catch (AdvancedJsonRpc\Error $e) {
} catch (AdvancedJsonRpc\Error $error) { // If a ResponseError is thrown, send it back in the Response
// If a ResponseError is thrown, send it back in the Response (result will be null) $error = $e;
$responseBody = new AdvancedJsonRpc\ErrorResponse($msg->body->id, $error);
} catch (Throwable $e) { } catch (Throwable $e) {
// If an unexpected error occured, send back an INTERNAL_ERROR error response // If an unexpected error occured, send back an INTERNAL_ERROR error response
$error = new AdvancedJsonRpc\Error($e->getMessage(), AdvancedJsonRpc\ErrorCode::INTERNAL_ERROR, null, $e); $error = new AdvancedJsonRpc\Error($e->getMessage(), AdvancedJsonRpc\ErrorCode::INTERNAL_ERROR, null, $e);
$responseBody = new AdvancedJsonRpc\ErrorResponse($msg->body->id, $error);
} }
// Only send a Response for a Request // Only send a Response for a Request
// Notifications do not send Responses // Notifications do not send Responses
if (AdvancedJsonRpc\Request::isRequest($msg->body)) { if (AdvancedJsonRpc\Request::isRequest($msg->body)) {
if ($error !== null) {
$responseBody = new AdvancedJsonRpc\ErrorResponse($msg->body->id, $error);
} else {
$responseBody = new AdvancedJsonRpc\SuccessResponse($msg->body->id, $result);
}
$this->protocolWriter->write(new Message($responseBody)); $this->protocolWriter->write(new Message($responseBody));
} }
}); });