forked from qt-creator/qt-creator
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:
@@ -431,9 +431,13 @@ void ClangModelManagerSupport::updateLanguageClient(
|
||||
const Client * const currentClient = LanguageClientManager::clientForDocument(doc);
|
||||
if (!settings.sizeIsOkay(doc->filePath()))
|
||||
continue;
|
||||
if (!currentClient || !currentClient->project()
|
||||
|| currentClient->state() != Client::Initialized
|
||||
|| project->isKnownFile(doc->filePath())) {
|
||||
if (currentClient && currentClient->project()
|
||||
&& currentClient->project() != project) {
|
||||
continue;
|
||||
}
|
||||
if (const Project * const docProject
|
||||
= SessionManager::projectForFile(doc->filePath());
|
||||
!docProject || docProject == project) {
|
||||
LanguageClientManager::openDocumentWithClient(doc, client);
|
||||
hasDocuments = true;
|
||||
}
|
||||
@@ -546,7 +550,8 @@ void ClangModelManagerSupport::claimNonProjectSources(ClangdClient *client)
|
||||
}
|
||||
if (!ClangdSettings::instance().sizeIsOkay(doc->filePath()))
|
||||
continue;
|
||||
client->openDocument(doc);
|
||||
if (!ProjectExplorer::SessionManager::projectForFile(doc->filePath()))
|
||||
LanguageClientManager::openDocumentWithClient(doc, client);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user