LanguageClient: do not assert on sending messages to a dying client

Fixes: QTCREATORBUG-29747
Change-Id: I14067695425d74eaeaa255b370ebf4106c0ac591
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
David Schulz
2023-10-13 10:42:30 +02:00
parent 184509228a
commit 085949bbae

View File

@@ -697,6 +697,12 @@ void Client::sendMessage(const JsonRpcMessage &message, SendDocUpdates sendUpdat
Schedule semanticTokensSchedule) Schedule semanticTokensSchedule)
{ {
QTC_ASSERT(d->m_clientInterface, return); 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);
const QString method = message.toJsonObject()[key].toString();
qCDebug(LOGLSPCLIENT) << "Ignoring message " << method << " because client is shutting down";
return;
}
QTC_ASSERT(d->m_state == Initialized, return); QTC_ASSERT(d->m_state == Initialized, return);
if (sendUpdates == SendDocUpdates::Send) if (sendUpdates == SendDocUpdates::Send)
d->sendPostponedDocumentUpdates(semanticTokensSchedule); d->sendPostponedDocumentUpdates(semanticTokensSchedule);