From 74cf082ee916db0bb6b3f465f2cdab4a36b6b9c5 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Wed, 18 Oct 2023 11:42:26 +0200 Subject: [PATCH] LanguageClient: properly deactivate documents for closing Clients Deactivating the documents resets all client specific data and objects in the document like the formatter or highlighting information. Fixes an assert in the LanguageClientFormatter. Change-Id: I7069abb273749ae335fed11010a5055eacaf58b2 Reviewed-by: Christian Stenger --- src/plugins/languageclient/languageclientmanager.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/plugins/languageclient/languageclientmanager.cpp b/src/plugins/languageclient/languageclientmanager.cpp index c05b84db4aa..839ececce7c 100644 --- a/src/plugins/languageclient/languageclientmanager.cpp +++ b/src/plugins/languageclient/languageclientmanager.cpp @@ -168,10 +168,10 @@ void LanguageClientManager::clientFinished(Client *client) const bool unexpectedFinish = client->state() != Client::Shutdown && client->state() != Client::ShutdownRequested; + const QList &clientDocs + = managerInstance->m_clientForDocument.keys(client); if (unexpectedFinish) { if (!PluginManager::isShuttingDown()) { - const QList &clientDocs - = managerInstance->m_clientForDocument.keys(client); if (client->state() == Client::Initialized && client->reset()) { qCDebug(Log) << "restart unexpectedly finished client: " << client->name() << client; client->log( @@ -186,10 +186,14 @@ void LanguageClientManager::clientFinished(Client *client) } qCDebug(Log) << "client finished unexpectedly: " << client->name() << client; client->log(Tr::tr("Unexpectedly finished.")); - for (TextEditor::TextDocument *document : clientDocs) - managerInstance->m_clientForDocument.remove(document); } } + + if (unexpectedFinish || !QTC_GUARD(clientDocs.isEmpty())) { + for (TextEditor::TextDocument *document : clientDocs) + openDocumentWithClient(document, nullptr); + } + deleteClient(client); if (isShutdownFinished()) emit managerInstance->shutdownFinished();