LanguageClient: report error for requests on unreachable server

Change-Id: I5444279b544a1aab3896f9e12ab7cad595a49267
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
David Schulz
2023-10-13 15:34:47 +02:00
parent 085949bbae
commit eab779d13a

View File

@@ -696,6 +696,20 @@ void Client::openDocument(TextEditor::TextDocument *document)
void Client::sendMessage(const JsonRpcMessage &message, SendDocUpdates sendUpdates,
Schedule semanticTokensSchedule)
{
QScopeGuard guard([responseHandler = message.responseHandler()](){
if (responseHandler) {
static ResponseError<std::nullptr_t> error;
if (!error.isValid()) {
error.setCode(-32803); // RequestFailed
error.setMessage("The server is currently in an unreachable state.");
}
QJsonObject response;
response[idKey] = responseHandler->id;
response[errorKey] = QJsonObject(error);
responseHandler->callback(JsonRpcMessage(response));
}
});
QTC_ASSERT(d->m_clientInterface, return);
if (d->m_state == Shutdown || d->m_state == ShutdownRequested) {
auto key = message.toJsonObject().contains(methodKey) ? QString(methodKey) : QString(idKey);
@@ -704,6 +718,8 @@ void Client::sendMessage(const JsonRpcMessage &message, SendDocUpdates sendUpdat
return;
}
QTC_ASSERT(d->m_state == Initialized, return);
guard.dismiss();
if (sendUpdates == SendDocUpdates::Send)
d->sendPostponedDocumentUpdates(semanticTokensSchedule);
if (std::optional<ResponseHandler> responseHandler = message.responseHandler())