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 <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2024-06-18 07:44:53 +02:00
parent c1c462ab11
commit c246cb8708

View File

@@ -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<std::nullptr_t> 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);
}
});