Copilot: shutdown plugin asynchronously

Wait for the client to finish. This fixes a crash when running the
plugin unit tests of the copilot plugin.

Change-Id: Id0805cb628a79316cd904350bb159ff1369a03b9
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2023-05-23 09:32:33 +02:00
parent 00d156c8ca
commit 305fae9a4a
3 changed files with 16 additions and 1 deletions

View File

@@ -60,5 +60,13 @@ void CopilotPlugin::restartClient()
CopilotSettings::instance().distPath()); CopilotSettings::instance().distPath());
} }
ExtensionSystem::IPlugin::ShutdownFlag CopilotPlugin::aboutToShutdown()
{
if (!m_client)
return SynchronousShutdown;
connect(m_client, &QObject::destroyed, this, &IPlugin::asynchronousShutdownFinished);
return AsynchronousShutdown;
}
} // namespace Internal } // namespace Internal
} // namespace Copilot } // namespace Copilot

View File

@@ -21,6 +21,7 @@ public:
void initialize() override; void initialize() override;
void extensionsInitialized() override; void extensionsInitialized() override;
void restartClient(); void restartClient();
ShutdownFlag aboutToShutdown() override;
private: private:
QPointer<CopilotClient> m_client; QPointer<CopilotClient> m_client;

View File

@@ -237,7 +237,13 @@ void LanguageClientManager::deleteClient(Client *client)
managerInstance->m_clients.removeAll(client); managerInstance->m_clients.removeAll(client);
for (QList<Client *> &clients : managerInstance->m_clientsForSetting) for (QList<Client *> &clients : managerInstance->m_clientsForSetting)
clients.removeAll(client); clients.removeAll(client);
client->deleteLater();
// a deleteLater is not sufficient here as it pastes the delete later event at the end
// of the main event loop and when the plugins are shutdown we spawn an additional eventloop
// that will not handle the delete later event. Use invokeMethod with Qt::QueuedConnection
// instead.
QMetaObject::invokeMethod(client, [client] {delete client;}, Qt::QueuedConnection);
if (!PluginManager::isShuttingDown()) if (!PluginManager::isShuttingDown())
emit instance()->clientRemoved(client); emit instance()->clientRemoved(client);
} }