LanguageClient: track clients scheduled for deletion

So report an async shutdown if we have clients scheduled for deletion
and wait until all clients have been fully deleted.

Change-Id: I40d35d3429003ab2a5c68cb81486c3e16b5f6f63
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
David Schulz
2023-05-23 11:02:15 +02:00
parent 38c64e5419
commit 3541b692f5
3 changed files with 28 additions and 3 deletions

View File

@@ -189,7 +189,7 @@ void LanguageClientManager::clientFinished(Client *client)
}
}
deleteClient(client);
if (PluginManager::isShuttingDown() && managerInstance->m_clients.isEmpty())
if (isShutdownFinished())
emit managerInstance->shutdownFinished();
}
@@ -243,6 +243,7 @@ void LanguageClientManager::deleteClient(Client *client)
// that will not handle the delete later event. Use invokeMethod with Qt::QueuedConnection
// instead.
QMetaObject::invokeMethod(client, [client] {delete client;}, Qt::QueuedConnection);
managerInstance->trackClientDeletion(client);
if (!PluginManager::isShuttingDown())
emit instance()->clientRemoved(client);
@@ -608,4 +609,24 @@ void LanguageClientManager::projectAdded(ProjectExplorer::Project *project)
client->projectOpened(project);
}
void LanguageClientManager::trackClientDeletion(Client *client)
{
QTC_ASSERT(!m_scheduledForDeletion.contains(client->id()), return);
m_scheduledForDeletion.insert(client->id());
connect(client, &QObject::destroyed, [this, id = client->id()](){
m_scheduledForDeletion.remove(id);
if (isShutdownFinished())
emit shutdownFinished();
});
}
bool LanguageClientManager::isShutdownFinished()
{
if (!PluginManager::isShuttingDown())
return false;
QTC_ASSERT(managerInstance, return true);
return managerInstance->m_clients.isEmpty()
&& managerInstance->m_scheduledForDeletion.isEmpty();
}
} // namespace LanguageClient