forked from qt-creator/qt-creator
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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user