ClangCodeModel: Start fallback clangd on demand

E.g. when a non-project source file is opened.

Fixes: QTCREATORBUG-29576
Change-Id: Ia99346a7a1016c4c7dcdb41ad6c8dbbc85ed95ff
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Christian Kandeler
2023-09-22 14:14:45 +02:00
parent 658e2a3197
commit 25c7390d0a

View File

@@ -231,10 +231,10 @@ ClangModelManagerSupport::ClangModelManagerSupport()
connect(modelManager, &CppModelManager::fallbackProjectPartUpdated, this, [this] {
if (sessionModeEnabled())
return;
if (ClangdClient * const fallbackClient = clientForProject(nullptr)) {
if (ClangdClient * const fallbackClient = clientForProject(nullptr))
LanguageClientManager::shutdownClient(fallbackClient);
if (ClangdSettings::instance().useClangd())
claimNonProjectSources(new ClangdClient(nullptr, {}));
}
});
auto projectManager = ProjectManager::instance();
@@ -251,9 +251,6 @@ ClangModelManagerSupport::ClangModelManagerSupport()
connect(&ClangdSettings::instance(), &ClangdSettings::changed,
this, &ClangModelManagerSupport::onClangdSettingsChanged);
if (ClangdSettings::instance().useClangd())
new ClangdClient(nullptr, {});
new ClangdQuickFixFactory(); // memory managed by CppEditor::g_cppQuickFixFactories
}
@@ -777,7 +774,12 @@ void ClangModelManagerSupport::onEditorOpened(IEditor *editor)
project = nullptr;
else if (!project && ProjectFile::isHeader(document->filePath()))
project = fallbackProject();
if (ClangdClient * const client = clientForProject(project))
ClangdClient *client = clientForProject(project);
if (!client) {
if (project)
return;
client = new ClangdClient(nullptr, {});
}
LanguageClientManager::openDocumentWithClient(textDocument, client);
}
}