From c246cb87084646d28702add0c7609fbb47879356 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Tue, 18 Jun 2024 07:44:53 +0200 Subject: [PATCH] LanguageClient: postpone unreachable server error reporting Since the overall nature of the communication is asynchronous calling functions might not expect that an error is reported from within the sendMessage function. Fixes: QTCREATORBUG-31054 Change-Id: Ie73510eb632408a9f7a9367c3a3e47ad021da7fe Reviewed-by: Christian Kandeler --- src/plugins/languageclient/client.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index c12693e4808..2ec4d41dbf3 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -735,7 +735,7 @@ void Client::openDocument(TextEditor::TextDocument *document) void Client::sendMessage(const JsonRpcMessage &message, SendDocUpdates sendUpdates, Schedule semanticTokensSchedule) { - QScopeGuard guard([responseHandler = message.responseHandler()](){ + QScopeGuard guard([this, responseHandler = message.responseHandler()](){ if (responseHandler) { static ResponseError error; if (!error.isValid()) { @@ -745,7 +745,9 @@ void Client::sendMessage(const JsonRpcMessage &message, SendDocUpdates sendUpdat QJsonObject response; response[idKey] = responseHandler->id; response[errorKey] = QJsonObject(error); - responseHandler->callback(JsonRpcMessage(response)); + QMetaObject::invokeMethod(this, [callback = responseHandler->callback, response](){ + callback(JsonRpcMessage(response)); + }, Qt::QueuedConnection); } });