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 <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2021-01-25 12:39:58 +01:00
parent e5982d9c3d
commit 58ff83b85b

View File

@@ -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<Core::IDocument *> &openedDocuments = Core::DocumentModel::openedDocuments();
QHash<ProjectExplorer::Project *, Client *> clientForProject;
for (Core::IDocument *document : openedDocuments) {
auto textDocument = qobject_cast<TextEditor::TextDocument *>(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);
}
}
}