From 58ff83b85b2d2b2c86060c8914343ec7420c33f8 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 25 Jan 2021 12:39:58 +0100 Subject: [PATCH] LanguageClient: Fix restarting server that needs a project Do not open the server for every open document that belongs to that server and assign the documents to the correct servers. Change-Id: I88a743489e7e4b396a112ad772926e90b22626f3 Reviewed-by: Christian Stenger --- .../languageclient/languageclientmanager.cpp | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/plugins/languageclient/languageclientmanager.cpp b/src/plugins/languageclient/languageclientmanager.cpp index b25d570b9c2..d8c55a12d8d 100644 --- a/src/plugins/languageclient/languageclientmanager.cpp +++ b/src/plugins/languageclient/languageclientmanager.cpp @@ -253,13 +253,24 @@ void LanguageClientManager::applySettings() break; } case BaseSettings::RequiresProject: { - for (Core::IDocument *doc : Core::DocumentModel::openedDocuments()) { - if (setting->m_languageFilter.isSupported(doc)) { - const Utils::FilePath filePath = doc->filePath(); - for (ProjectExplorer::Project *project : - ProjectExplorer::SessionManager::projects()) { - if (project->isKnownFile(filePath)) - startClient(setting, project); + const QList &openedDocuments = Core::DocumentModel::openedDocuments(); + QHash clientForProject; + for (Core::IDocument *document : openedDocuments) { + auto textDocument = qobject_cast(document); + if (!textDocument || !setting->m_languageFilter.isSupported(textDocument)) + continue; + const Utils::FilePath filePath = textDocument->filePath(); + for (ProjectExplorer::Project *project : + ProjectExplorer::SessionManager::projects()) { + if (project->isKnownFile(filePath)) { + Client *client = clientForProject[project]; + if (!client) { + client = startClient(setting, project); + if (!client) + continue; + clientForProject[project] = client; + } + client->openDocument(textDocument); } } }