forked from qt-creator/qt-creator
Clangd: Handle settings changes
Users no longer have to re-load a project for settings changes to take effect. Change-Id: I86dccccac14a30514c8dac292c7765ee4806f6ba Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -33,7 +33,6 @@
|
||||
#include <coreplugin/find/searchresultitem.h>
|
||||
#include <coreplugin/find/searchresultwindow.h>
|
||||
#include <cplusplus/FindUsages.h>
|
||||
#include <cpptools/cppcodemodelsettings.h>
|
||||
#include <cpptools/cppeditorwidgetinterface.h>
|
||||
#include <cpptools/cppfindreferences.h>
|
||||
#include <cpptools/cpptoolsreuse.h>
|
||||
@@ -419,7 +418,7 @@ public:
|
||||
static BaseClientInterface *clientInterface(Project *project, const Utils::FilePath &jsonDbDir)
|
||||
{
|
||||
QString indexingOption = "--background-index";
|
||||
const CppTools::ClangdSettings settings = CppTools::ClangdProjectSettings(project).settings();
|
||||
const CppTools::ClangdSettings settings(CppTools::ClangdProjectSettings(project).settings());
|
||||
if (!settings.indexingEnabled())
|
||||
indexingOption += "=0";
|
||||
Utils::CommandLine cmd{settings.clangdFilePath(), {indexingOption, "--limit-results=0"}};
|
||||
@@ -661,7 +660,8 @@ public:
|
||||
class ClangdClient::Private
|
||||
{
|
||||
public:
|
||||
Private(ClangdClient *q) : q(q) {}
|
||||
Private(ClangdClient *q, Project *project)
|
||||
: q(q), settings(CppTools::ClangdProjectSettings(project).settings()) {}
|
||||
|
||||
void handleFindUsagesResult(quint64 key, const QList<Location> &locations);
|
||||
static void handleRenameRequest(const SearchResult *search,
|
||||
@@ -689,6 +689,7 @@ public:
|
||||
const QString &type = {});
|
||||
|
||||
ClangdClient * const q;
|
||||
const CppTools::ClangdSettings::Data settings;
|
||||
QHash<quint64, ReferencesData> runningFindUsages;
|
||||
Utils::optional<FollowSymbolData> followSymbolData;
|
||||
Utils::optional<SwitchDeclDefData> switchDeclDefData;
|
||||
@@ -700,7 +701,7 @@ public:
|
||||
};
|
||||
|
||||
ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir)
|
||||
: Client(clientInterface(project, jsonDbDir)), d(new Private(this))
|
||||
: Client(clientInterface(project, jsonDbDir)), d(new Private(this, project))
|
||||
{
|
||||
setName(tr("clangd"));
|
||||
LanguageFilter langFilter;
|
||||
@@ -900,6 +901,8 @@ QVersionNumber ClangdClient::versionNumber() const
|
||||
return d->versionNumber.value();
|
||||
}
|
||||
|
||||
CppTools::ClangdSettings::Data ClangdClient::settingsData() const { return d->settings; }
|
||||
|
||||
void ClangdClient::Private::handleFindUsagesResult(quint64 key, const QList<Location> &locations)
|
||||
{
|
||||
const auto refData = runningFindUsages.find(key);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cpptools/cppcodemodelsettings.h>
|
||||
#include <cpptools/refactoringengineinterface.h>
|
||||
#include <languageclient/client.h>
|
||||
#include <utils/link.h>
|
||||
@@ -49,6 +50,7 @@ public:
|
||||
|
||||
bool isFullyIndexed() const;
|
||||
QVersionNumber versionNumber() const;
|
||||
CppTools::ClangdSettings::Data settingsData() const;
|
||||
|
||||
void openExtraFile(const Utils::FilePath &filePath, const QString &content = {});
|
||||
void closeExtraFile(const Utils::FilePath &filePath);
|
||||
|
||||
@@ -122,6 +122,8 @@ ClangModelManagerSupport::ClangModelManagerSupport()
|
||||
|
||||
CppTools::ClangdSettings::setDefaultClangdPath(Utils::FilePath::fromString(
|
||||
Core::ICore::clangdExecutable(CLANG_BINDIR)));
|
||||
connect(&CppTools::ClangdSettings::instance(), &CppTools::ClangdSettings::changed,
|
||||
this, &ClangModelManagerSupport::onClangdSettingsChanged);
|
||||
CppTools::CppCodeModelSettings *settings = CppTools::codeModelSettings();
|
||||
connect(settings, &CppTools::CppCodeModelSettings::clangDiagnosticConfigsInvalidated,
|
||||
this, &ClangModelManagerSupport::onDiagnosticConfigsInvalidated);
|
||||
@@ -247,7 +249,7 @@ void ClangModelManagerSupport::connectToWidgetsMarkContextMenuRequested(QWidget
|
||||
void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *project,
|
||||
const CppTools::ProjectInfo &projectInfo)
|
||||
{
|
||||
if (!CppTools::ClangdProjectSettings(project).settings().useClangd())
|
||||
if (!CppTools::ClangdProjectSettings(project).settings().useClangd)
|
||||
return;
|
||||
const auto getJsonDbDir = [project] {
|
||||
if (const ProjectExplorer::Target * const target = project->activeTarget()) {
|
||||
@@ -268,7 +270,7 @@ void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *pr
|
||||
generatorWatcher->deleteLater();
|
||||
if (!ProjectExplorer::SessionManager::hasProject(project))
|
||||
return;
|
||||
if (!CppTools::ClangdProjectSettings(project).settings().useClangd())
|
||||
if (!CppTools::ClangdProjectSettings(project).settings().useClangd)
|
||||
return;
|
||||
if (cppModelManager()->projectInfo(project) != projectInfo)
|
||||
return;
|
||||
@@ -288,7 +290,7 @@ void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *pr
|
||||
using namespace ProjectExplorer;
|
||||
if (!SessionManager::hasProject(project))
|
||||
return;
|
||||
if (!CppTools::ClangdProjectSettings(project).settings().useClangd())
|
||||
if (!CppTools::ClangdProjectSettings(project).settings().useClangd)
|
||||
return;
|
||||
if (cppModelManager()->projectInfo(project) != projectInfo)
|
||||
return;
|
||||
@@ -587,6 +589,27 @@ void ClangModelManagerSupport::onProjectPartsRemoved(const QStringList &projectP
|
||||
reinitializeBackendDocuments(projectPartIds);
|
||||
}
|
||||
|
||||
void ClangModelManagerSupport::onClangdSettingsChanged()
|
||||
{
|
||||
// TODO: Handle also project-less client
|
||||
for (ProjectExplorer::Project * const project : ProjectExplorer::SessionManager::projects()) {
|
||||
const CppTools::ClangdSettings settings(
|
||||
CppTools::ClangdProjectSettings(project).settings());
|
||||
ClangdClient * const client = clientForProject(project);
|
||||
if (!client) {
|
||||
if (settings.useClangd())
|
||||
updateLanguageClient(project, cppModelManager()->projectInfo(project));
|
||||
continue;
|
||||
}
|
||||
if (!settings.useClangd()) {
|
||||
LanguageClientManager::shutdownClient(client);
|
||||
continue;
|
||||
}
|
||||
if (client->settingsData() != settings.data())
|
||||
updateLanguageClient(project, cppModelManager()->projectInfo(project));
|
||||
}
|
||||
}
|
||||
|
||||
static ClangEditorDocumentProcessors clangProcessorsWithDiagnosticConfig(
|
||||
const QVector<::Utils::Id> &configIds)
|
||||
{
|
||||
|
||||
@@ -114,6 +114,7 @@ private:
|
||||
|
||||
void onProjectPartsUpdated(ProjectExplorer::Project *project);
|
||||
void onProjectPartsRemoved(const QStringList &projectPartIds);
|
||||
void onClangdSettingsChanged();
|
||||
|
||||
void onDiagnosticConfigsInvalidated(const QVector<::Utils::Id> &configIds);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user