ClangCodeModel: Prevent documents from getting opened in wrong clangd

As per 8ad7ab2d2a, we prefer to open non-
project sources in a project-specific clangd, rather than the fallback
client.
However, we do *not* want clangd to open files from "foreign" projects.
Checking for the existence of a client for a specific file is not enough,
as we might be in the process of loading a session or the respective
project might have clangd turned off.

Change-Id: I2d5cb7027c6a3ad23e99606d6d6742d67fbc5384
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Christian Kandeler
2022-07-04 13:39:33 +02:00
parent 22ed2aa8ac
commit 96be267a6e

View File

@@ -431,9 +431,13 @@ void ClangModelManagerSupport::updateLanguageClient(
const Client * const currentClient = LanguageClientManager::clientForDocument(doc); const Client * const currentClient = LanguageClientManager::clientForDocument(doc);
if (!settings.sizeIsOkay(doc->filePath())) if (!settings.sizeIsOkay(doc->filePath()))
continue; continue;
if (!currentClient || !currentClient->project() if (currentClient && currentClient->project()
|| currentClient->state() != Client::Initialized && currentClient->project() != project) {
|| project->isKnownFile(doc->filePath())) { continue;
}
if (const Project * const docProject
= SessionManager::projectForFile(doc->filePath());
!docProject || docProject == project) {
LanguageClientManager::openDocumentWithClient(doc, client); LanguageClientManager::openDocumentWithClient(doc, client);
hasDocuments = true; hasDocuments = true;
} }
@@ -546,7 +550,8 @@ void ClangModelManagerSupport::claimNonProjectSources(ClangdClient *client)
} }
if (!ClangdSettings::instance().sizeIsOkay(doc->filePath())) if (!ClangdSettings::instance().sizeIsOkay(doc->filePath()))
continue; continue;
client->openDocument(doc); if (!ProjectExplorer::SessionManager::projectForFile(doc->filePath()))
LanguageClientManager::openDocumentWithClient(doc, client);
} }
} }