forked from qt-creator/qt-creator
ClangCodeModel: Try to correct unexpected ClangdClient count
Ideally, it should not happen that there is more than one client per project, but if it does, try to fix the situation by choosing the "best" one and shutting down the others. Change-Id: If00924925afabf6bc7efe7f33da693db323a00d8 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -388,6 +388,18 @@ ClangdClient *ClangModelManagerSupport::clientForProject(
|
||||
&& c->state() != Client::Shutdown;
|
||||
});
|
||||
QTC_ASSERT(clients.size() <= 1, qDebug() << project << clients.size());
|
||||
if (clients.size() > 1) {
|
||||
Client *activeClient = nullptr;
|
||||
for (Client * const c : clients) {
|
||||
if (!activeClient && (c->state() == Client::Initialized
|
||||
|| c->state() == Client::InitializeRequested)) {
|
||||
activeClient = c;
|
||||
} else {
|
||||
LanguageClientManager::shutdownClient(c);
|
||||
}
|
||||
}
|
||||
return qobject_cast<ClangdClient *>(activeClient);
|
||||
}
|
||||
return clients.empty() ? nullptr : qobject_cast<ClangdClient *>(clients.first());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user