From eab779d13adbaef5d1e5215e180051689152a4dc Mon Sep 17 00:00:00 2001 From: David Schulz Date: Fri, 13 Oct 2023 15:34:47 +0200 Subject: [PATCH] LanguageClient: report error for requests on unreachable server Change-Id: I5444279b544a1aab3896f9e12ab7cad595a49267 Reviewed-by: Jarek Kobus Reviewed-by: --- src/plugins/languageclient/client.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index e6ee9cf6d18..6c6098be215 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -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 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 = message.responseHandler())