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