Clangd: Add per-project settings

Users might want to use clangd for certain project, but not for others.

Change-Id: Id29ce3349f0acd359cf7c824ece073b147ed2280
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-06-28 14:55:54 +02:00
parent b3c83b79f7
commit fbb804c442
10 changed files with 286 additions and 94 deletions

View File

@@ -416,15 +416,15 @@ public:
: Request("textDocument/symbolInfo", params) {}
};
static BaseClientInterface *clientInterface(const Utils::FilePath &jsonDbDir)
static BaseClientInterface *clientInterface(Project *project, const Utils::FilePath &jsonDbDir)
{
QString indexingOption = "--background-index";
if (!CppTools::ClangdSettings::indexingEnabled())
const CppTools::ClangdSettings settings = CppTools::ClangdProjectSettings(project).settings();
if (!settings.indexingEnabled())
indexingOption += "=0";
Utils::CommandLine cmd{CppTools::ClangdSettings::clangdFilePath(),
{indexingOption, "--limit-results=0"}};
if (CppTools::ClangdSettings::workerThreadLimit() != 0)
cmd.addArg("-j=" + QString::number(CppTools::ClangdSettings::workerThreadLimit()));
Utils::CommandLine cmd{settings.clangdFilePath(), {indexingOption, "--limit-results=0"}};
if (settings.workerThreadLimit() != 0)
cmd.addArg("-j=" + QString::number(settings.workerThreadLimit()));
if (!jsonDbDir.isEmpty())
cmd.addArg("--compile-commands-dir=" + jsonDbDir.toString());
if (clangdLog().isDebugEnabled())
@@ -700,7 +700,7 @@ public:
};
ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir)
: Client(clientInterface(jsonDbDir)), d(new Private(this))
: Client(clientInterface(project, jsonDbDir)), d(new Private(this))
{
setName(tr("clangd"));
LanguageFilter langFilter;

View File

@@ -247,7 +247,7 @@ void ClangModelManagerSupport::connectToWidgetsMarkContextMenuRequested(QWidget
void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *project,
const CppTools::ProjectInfo &projectInfo)
{
if (!CppTools::ClangdSettings::useClangd())
if (!CppTools::ClangdProjectSettings(project).settings().useClangd())
return;
const auto getJsonDbDir = [project] {
if (const ProjectExplorer::Target * const target = project->activeTarget()) {
@@ -266,10 +266,10 @@ void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *pr
connect(generatorWatcher, &QFutureWatcher<GenerateCompilationDbResult>::finished,
[this, project, projectInfo, getJsonDbDir, jsonDbDir, generatorWatcher] {
generatorWatcher->deleteLater();
if (!CppTools::ClangdSettings::useClangd())
return;
if (!ProjectExplorer::SessionManager::hasProject(project))
return;
if (!CppTools::ClangdProjectSettings(project).settings().useClangd())
return;
if (cppModelManager()->projectInfo(project) != projectInfo)
return;
if (getJsonDbDir() != jsonDbDir)
@@ -286,10 +286,10 @@ void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *pr
ClangdClient * const client = createClient(project, jsonDbDir);
connect(client, &Client::initialized, this, [client, project, projectInfo, jsonDbDir] {
using namespace ProjectExplorer;
if (!CppTools::ClangdSettings::useClangd())
return;
if (!SessionManager::hasProject(project))
return;
if (!CppTools::ClangdProjectSettings(project).settings().useClangd())
return;
if (cppModelManager()->projectInfo(project) != projectInfo)
return;

View File

@@ -88,7 +88,7 @@ void ClangdTest::initTestCase()
const QString clangdFromEnv = qEnvironmentVariable("QTC_CLANGD");
if (!clangdFromEnv.isEmpty())
CppTools::ClangdSettings::setClangdFilePath(Utils::FilePath::fromString(clangdFromEnv));
const auto clangd = CppTools::ClangdSettings::clangdFilePath();
const auto clangd = CppTools::ClangdSettings::instance().clangdFilePath();
if (clangd.isEmpty() || !clangd.exists())
QSKIP("clangd binary not found");
CppTools::ClangdSettings::setUseClangd(true);