2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2013-09-06 13:14:15 +02:00
|
|
|
|
|
|
|
|
#include "cppcodemodelsettingspage.h"
|
2016-02-22 17:18:18 +01:00
|
|
|
|
2022-05-19 14:48:09 +02:00
|
|
|
#include "clangdiagnosticconfigsselectionwidget.h"
|
2016-02-22 17:18:18 +01:00
|
|
|
#include "clangdiagnosticconfigswidget.h"
|
2021-08-30 10:58:08 +02:00
|
|
|
#include "cppeditorconstants.h"
|
2023-01-11 20:43:10 +01:00
|
|
|
#include "cppeditortr.h"
|
2019-01-10 11:38:06 +01:00
|
|
|
#include "cpptoolsreuse.h"
|
2013-09-06 13:14:15 +02:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
2023-05-23 15:05:38 +02:00
|
|
|
#include <coreplugin/session.h>
|
2022-07-12 18:21:44 +02:00
|
|
|
|
2014-06-16 18:25:52 +04:00
|
|
|
#include <utils/algorithm.h>
|
2021-10-07 16:15:08 +02:00
|
|
|
#include <utils/infolabel.h>
|
2021-11-23 17:04:13 +01:00
|
|
|
#include <utils/itemviews.h>
|
2022-07-12 18:21:44 +02:00
|
|
|
#include <utils/layoutbuilder.h>
|
2021-06-25 16:50:52 +02:00
|
|
|
#include <utils/pathchooser.h>
|
2021-11-23 17:04:13 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2013-09-06 13:14:15 +02:00
|
|
|
|
2022-07-12 18:21:44 +02:00
|
|
|
#include <QCheckBox>
|
2022-09-21 11:17:07 +02:00
|
|
|
#include <QComboBox>
|
2022-05-16 16:40:29 +02:00
|
|
|
#include <QDesktopServices>
|
2021-06-25 16:50:52 +02:00
|
|
|
#include <QFormLayout>
|
2021-11-23 17:04:13 +01:00
|
|
|
#include <QGroupBox>
|
|
|
|
|
#include <QInputDialog>
|
|
|
|
|
#include <QPushButton>
|
2021-06-25 18:16:08 +02:00
|
|
|
#include <QSpinBox>
|
2021-11-23 17:04:13 +01:00
|
|
|
#include <QStringListModel>
|
2013-09-06 13:14:15 +02:00
|
|
|
#include <QTextStream>
|
2021-11-23 17:04:13 +01:00
|
|
|
#include <QVBoxLayout>
|
2021-10-07 16:15:08 +02:00
|
|
|
#include <QVersionNumber>
|
2022-10-14 17:27:14 +02:00
|
|
|
#include <QTextBlock>
|
2013-09-06 13:14:15 +02:00
|
|
|
|
2022-03-29 15:47:10 +02:00
|
|
|
#include <limits>
|
|
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
namespace CppEditor::Internal {
|
2013-09-06 13:14:15 +02:00
|
|
|
|
2020-01-17 15:15:24 +01:00
|
|
|
class CppCodeModelSettingsWidget final : public Core::IOptionsPageWidget
|
2013-09-06 13:14:15 +02:00
|
|
|
{
|
2020-01-17 15:15:24 +01:00
|
|
|
public:
|
2020-02-03 11:13:27 +01:00
|
|
|
CppCodeModelSettingsWidget(CppCodeModelSettings *s);
|
2013-09-06 13:14:15 +02:00
|
|
|
|
2020-01-17 15:15:24 +01:00
|
|
|
private:
|
|
|
|
|
void apply() final;
|
|
|
|
|
|
|
|
|
|
bool applyGeneralWidgetsToSettings() const;
|
|
|
|
|
|
2020-02-03 11:13:27 +01:00
|
|
|
CppCodeModelSettings *m_settings = nullptr;
|
2022-07-12 18:21:44 +02:00
|
|
|
QCheckBox *m_interpretAmbiguousHeadersAsCHeaders;
|
|
|
|
|
QCheckBox *m_ignorePchCheckBox;
|
2022-09-06 17:52:22 +02:00
|
|
|
QCheckBox *m_useBuiltinPreprocessorCheckBox;
|
2022-07-12 18:21:44 +02:00
|
|
|
QCheckBox *m_skipIndexingBigFilesCheckBox;
|
|
|
|
|
QSpinBox *m_bigFilesLimitSpinBox;
|
2022-10-14 17:27:14 +02:00
|
|
|
QCheckBox *m_ignoreFilesCheckBox;
|
|
|
|
|
QPlainTextEdit *m_ignorePatternTextEdit;
|
2020-01-17 15:15:24 +01:00
|
|
|
};
|
|
|
|
|
|
2020-02-03 11:13:27 +01:00
|
|
|
CppCodeModelSettingsWidget::CppCodeModelSettingsWidget(CppCodeModelSettings *s)
|
2022-07-12 18:21:44 +02:00
|
|
|
: m_settings(s)
|
2013-09-06 13:14:15 +02:00
|
|
|
{
|
2022-07-12 18:21:44 +02:00
|
|
|
m_interpretAmbiguousHeadersAsCHeaders
|
2023-01-11 20:43:10 +01:00
|
|
|
= new QCheckBox(Tr::tr("Interpret ambiguous headers as C headers"));
|
2020-01-17 15:15:24 +01:00
|
|
|
|
2023-01-11 20:43:10 +01:00
|
|
|
m_skipIndexingBigFilesCheckBox = new QCheckBox(Tr::tr("Do not index files greater than"));
|
2022-07-12 18:21:44 +02:00
|
|
|
m_skipIndexingBigFilesCheckBox->setChecked(m_settings->skipIndexingBigFiles());
|
2013-09-06 13:14:15 +02:00
|
|
|
|
2022-07-12 18:21:44 +02:00
|
|
|
m_bigFilesLimitSpinBox = new QSpinBox;
|
2023-01-11 20:43:10 +01:00
|
|
|
m_bigFilesLimitSpinBox->setSuffix(Tr::tr("MB"));
|
2022-07-12 18:21:44 +02:00
|
|
|
m_bigFilesLimitSpinBox->setRange(1, 500);
|
|
|
|
|
m_bigFilesLimitSpinBox->setValue(m_settings->indexerFileSizeLimitInMb());
|
2013-09-06 13:14:15 +02:00
|
|
|
|
2023-01-11 20:43:10 +01:00
|
|
|
m_ignoreFilesCheckBox = new QCheckBox(Tr::tr("Ignore files"));
|
2023-05-26 10:17:38 +02:00
|
|
|
m_ignoreFilesCheckBox->setToolTip(
|
|
|
|
|
"<html><head/><body><p>"
|
|
|
|
|
+ Tr::tr("Ignore files that match these wildcard patterns, one wildcard per line.")
|
|
|
|
|
+ "</p></body></html>");
|
2022-10-14 17:27:14 +02:00
|
|
|
|
|
|
|
|
m_ignoreFilesCheckBox->setChecked(m_settings->ignoreFiles());
|
|
|
|
|
m_ignorePatternTextEdit = new QPlainTextEdit(m_settings->ignorePattern());
|
|
|
|
|
m_ignorePatternTextEdit->setToolTip(m_ignoreFilesCheckBox->toolTip());
|
|
|
|
|
m_ignorePatternTextEdit->setEnabled(m_ignoreFilesCheckBox->isChecked());
|
|
|
|
|
|
2023-08-01 19:49:35 +02:00
|
|
|
connect(m_ignoreFilesCheckBox, &QCheckBox::stateChanged, this, [this] {
|
2022-10-14 17:27:14 +02:00
|
|
|
m_ignorePatternTextEdit->setEnabled(m_ignoreFilesCheckBox->isChecked());
|
|
|
|
|
});
|
|
|
|
|
|
2023-01-11 20:43:10 +01:00
|
|
|
m_ignorePchCheckBox = new QCheckBox(Tr::tr("Ignore precompiled headers"));
|
|
|
|
|
m_ignorePchCheckBox->setToolTip(Tr::tr(
|
2022-07-12 18:21:44 +02:00
|
|
|
"<html><head/><body><p>When precompiled headers are not ignored, the parsing for code "
|
|
|
|
|
"completion and semantic highlighting will process the precompiled header before "
|
|
|
|
|
"processing any file.</p></body></html>"));
|
|
|
|
|
|
2023-01-11 20:43:10 +01:00
|
|
|
m_useBuiltinPreprocessorCheckBox = new QCheckBox(Tr::tr("Use built-in preprocessor to show "
|
|
|
|
|
"pre-processed files"));
|
2022-09-06 17:52:22 +02:00
|
|
|
m_useBuiltinPreprocessorCheckBox->setToolTip
|
2023-01-11 20:43:10 +01:00
|
|
|
(Tr::tr("Uncheck this to invoke the actual compiler "
|
|
|
|
|
"to show a pre-processed source file in the editor."));
|
2022-09-06 17:52:22 +02:00
|
|
|
|
2022-07-12 18:21:44 +02:00
|
|
|
m_interpretAmbiguousHeadersAsCHeaders->setChecked(
|
|
|
|
|
m_settings->interpretAmbigiousHeadersAsCHeaders());
|
|
|
|
|
|
|
|
|
|
m_ignorePchCheckBox->setChecked(m_settings->pchUsage() == CppCodeModelSettings::PchUse_None);
|
2022-09-06 17:52:22 +02:00
|
|
|
m_useBuiltinPreprocessorCheckBox->setChecked(m_settings->useBuiltinPreprocessor());
|
2022-07-12 18:21:44 +02:00
|
|
|
|
2023-04-25 10:15:07 +02:00
|
|
|
using namespace Layouting;
|
2022-07-12 18:21:44 +02:00
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
Group {
|
2023-01-11 20:43:10 +01:00
|
|
|
title(Tr::tr("General")),
|
2022-07-12 18:21:44 +02:00
|
|
|
Column {
|
|
|
|
|
m_interpretAmbiguousHeadersAsCHeaders,
|
|
|
|
|
m_ignorePchCheckBox,
|
2022-09-06 17:52:22 +02:00
|
|
|
m_useBuiltinPreprocessorCheckBox,
|
2022-07-22 18:54:04 +02:00
|
|
|
Row { m_skipIndexingBigFilesCheckBox, m_bigFilesLimitSpinBox, st },
|
2022-10-14 17:27:14 +02:00
|
|
|
Row { Column { m_ignoreFilesCheckBox, st }, m_ignorePatternTextEdit },
|
2022-07-12 18:21:44 +02:00
|
|
|
}
|
|
|
|
|
},
|
2022-07-22 18:54:04 +02:00
|
|
|
st
|
2022-07-12 18:21:44 +02:00
|
|
|
}.attachTo(this);
|
2020-01-17 15:15:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CppCodeModelSettingsWidget::apply()
|
2013-09-06 13:14:15 +02:00
|
|
|
{
|
2022-05-19 14:48:09 +02:00
|
|
|
if (applyGeneralWidgetsToSettings())
|
2013-09-06 13:14:15 +02:00
|
|
|
m_settings->toSettings(Core::ICore::settings());
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-12 18:01:12 +01:00
|
|
|
bool CppCodeModelSettingsWidget::applyGeneralWidgetsToSettings() const
|
2015-11-11 18:54:52 +01:00
|
|
|
{
|
2017-01-12 18:01:12 +01:00
|
|
|
bool settingsChanged = false;
|
2015-11-11 18:54:52 +01:00
|
|
|
|
2017-01-12 18:01:12 +01:00
|
|
|
const bool newInterpretAmbiguousHeaderAsCHeaders
|
2022-07-12 18:21:44 +02:00
|
|
|
= m_interpretAmbiguousHeadersAsCHeaders->isChecked();
|
2017-01-12 18:01:12 +01:00
|
|
|
if (m_settings->interpretAmbigiousHeadersAsCHeaders()
|
|
|
|
|
!= newInterpretAmbiguousHeaderAsCHeaders) {
|
|
|
|
|
m_settings->setInterpretAmbigiousHeadersAsCHeaders(newInterpretAmbiguousHeaderAsCHeaders);
|
|
|
|
|
settingsChanged = true;
|
2015-11-11 18:54:52 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-12 18:21:44 +02:00
|
|
|
const bool newSkipIndexingBigFiles = m_skipIndexingBigFilesCheckBox->isChecked();
|
2016-08-16 13:37:49 +02:00
|
|
|
if (m_settings->skipIndexingBigFiles() != newSkipIndexingBigFiles) {
|
|
|
|
|
m_settings->setSkipIndexingBigFiles(newSkipIndexingBigFiles);
|
|
|
|
|
settingsChanged = true;
|
|
|
|
|
}
|
2022-09-06 17:52:22 +02:00
|
|
|
const bool newUseBuiltinPreprocessor = m_useBuiltinPreprocessorCheckBox->isChecked();
|
|
|
|
|
if (m_settings->useBuiltinPreprocessor() != newUseBuiltinPreprocessor) {
|
|
|
|
|
m_settings->setUseBuiltinPreprocessor(newUseBuiltinPreprocessor);
|
|
|
|
|
settingsChanged = true;
|
|
|
|
|
}
|
2022-10-14 17:27:14 +02:00
|
|
|
const bool ignoreFiles = m_ignoreFilesCheckBox->isChecked();
|
|
|
|
|
if (m_settings->ignoreFiles() != ignoreFiles) {
|
|
|
|
|
m_settings->setIgnoreFiles(ignoreFiles);
|
|
|
|
|
settingsChanged = true;
|
|
|
|
|
}
|
|
|
|
|
const QString ignorePattern = m_ignorePatternTextEdit->toPlainText();
|
|
|
|
|
if (m_settings->ignorePattern() != ignorePattern) {
|
|
|
|
|
m_settings->setIgnorePattern(ignorePattern);
|
|
|
|
|
settingsChanged = true;
|
|
|
|
|
}
|
2022-07-12 18:21:44 +02:00
|
|
|
const int newFileSizeLimit = m_bigFilesLimitSpinBox->value();
|
2016-08-16 13:37:49 +02:00
|
|
|
if (m_settings->indexerFileSizeLimitInMb() != newFileSizeLimit) {
|
|
|
|
|
m_settings->setIndexerFileSizeLimitInMb(newFileSizeLimit);
|
|
|
|
|
settingsChanged = true;
|
2017-01-12 18:01:12 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-12 18:21:44 +02:00
|
|
|
const bool newIgnorePch = m_ignorePchCheckBox->isChecked();
|
2017-01-12 18:01:12 +01:00
|
|
|
const bool previousIgnorePch = m_settings->pchUsage() == CppCodeModelSettings::PchUse_None;
|
|
|
|
|
if (newIgnorePch != previousIgnorePch) {
|
2022-07-12 18:21:44 +02:00
|
|
|
const CppCodeModelSettings::PCHUsage pchUsage = m_ignorePchCheckBox->isChecked()
|
2017-01-12 18:01:12 +01:00
|
|
|
? CppCodeModelSettings::PchUse_None
|
|
|
|
|
: CppCodeModelSettings::PchUse_BuildSystem;
|
|
|
|
|
m_settings->setPCHUsage(pchUsage);
|
|
|
|
|
settingsChanged = true;
|
2016-08-16 13:37:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return settingsChanged;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-03 11:13:27 +01:00
|
|
|
CppCodeModelSettingsPage::CppCodeModelSettingsPage(CppCodeModelSettings *settings)
|
2013-09-06 13:14:15 +02:00
|
|
|
{
|
|
|
|
|
setId(Constants::CPP_CODE_MODEL_SETTINGS_ID);
|
2023-01-11 20:43:10 +01:00
|
|
|
setDisplayName(Tr::tr("Code Model"));
|
2013-09-06 13:14:15 +02:00
|
|
|
setCategory(Constants::CPP_SETTINGS_CATEGORY);
|
2023-01-11 20:43:10 +01:00
|
|
|
setDisplayCategory(Tr::tr("C++"));
|
2020-01-10 09:33:24 +01:00
|
|
|
setCategoryIconPath(":/projectexplorer/images/settingscategory_cpp.png");
|
2020-01-17 15:15:24 +01:00
|
|
|
setWidgetCreator([settings] { return new CppCodeModelSettingsWidget(settings); });
|
2013-09-06 13:14:15 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-28 14:55:54 +02:00
|
|
|
class ClangdSettingsWidget::Private
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QCheckBox useClangdCheckBox;
|
2022-09-21 11:17:07 +02:00
|
|
|
QComboBox indexingComboBox;
|
2023-05-17 13:45:56 +02:00
|
|
|
QComboBox headerSourceSwitchComboBox;
|
2021-10-27 11:03:42 +02:00
|
|
|
QCheckBox autoIncludeHeadersCheckBox;
|
2022-03-29 15:47:10 +02:00
|
|
|
QCheckBox sizeThresholdCheckBox;
|
2021-06-28 14:55:54 +02:00
|
|
|
QSpinBox threadLimitSpinBox;
|
2021-08-12 12:00:58 +02:00
|
|
|
QSpinBox documentUpdateThreshold;
|
2022-03-29 15:47:10 +02:00
|
|
|
QSpinBox sizeThresholdSpinBox;
|
2022-07-25 17:04:23 +02:00
|
|
|
QSpinBox completionResults;
|
2021-06-28 14:55:54 +02:00
|
|
|
Utils::PathChooser clangdChooser;
|
2021-10-07 16:15:08 +02:00
|
|
|
Utils::InfoLabel versionWarningLabel;
|
2022-05-19 14:48:09 +02:00
|
|
|
ClangDiagnosticConfigsSelectionWidget *configSelectionWidget = nullptr;
|
2021-11-23 17:04:13 +01:00
|
|
|
QGroupBox *sessionsGroupBox = nullptr;
|
|
|
|
|
QStringListModel sessionsModel;
|
2021-06-28 14:55:54 +02:00
|
|
|
};
|
2021-06-25 16:50:52 +02:00
|
|
|
|
2021-11-23 17:04:13 +01:00
|
|
|
ClangdSettingsWidget::ClangdSettingsWidget(const ClangdSettings::Data &settingsData,
|
|
|
|
|
bool isForProject)
|
2021-07-01 04:17:54 +02:00
|
|
|
: d(new Private)
|
2021-06-28 14:55:54 +02:00
|
|
|
{
|
2021-07-01 04:17:54 +02:00
|
|
|
const ClangdSettings settings(settingsData);
|
2023-01-11 20:43:10 +01:00
|
|
|
const QString indexingToolTip = Tr::tr(
|
2023-02-20 15:41:43 +01:00
|
|
|
"<p>If background indexing is enabled, global symbol searches will yield more accurate "
|
|
|
|
|
"results, at the cost of additional CPU load when the project is first opened. The "
|
|
|
|
|
"indexing result is persisted in the project's build directory. If you disable background "
|
|
|
|
|
"indexing, a faster, but less accurate, built-in indexer is used instead. The thread "
|
|
|
|
|
"priority for building the background index can be adjusted since clangd 15.</p>"
|
|
|
|
|
"<p>Background Priority: Minimum priority, runs on idle CPUs. May leave 'performance' "
|
|
|
|
|
"cores unused.</p>"
|
|
|
|
|
"<p>Normal Priority: Reduced priority compared to interactive work.</p>"
|
2022-09-21 11:17:07 +02:00
|
|
|
"Low Priority: Same priority as other clangd work.");
|
2023-05-17 13:45:56 +02:00
|
|
|
const QString headerSourceSwitchToolTip = Tr::tr(
|
|
|
|
|
"<p>Which C/C++ backend to use when switching between header and source file."
|
|
|
|
|
"<p>The clangd implementation has more capabilities, but also has some bugs not present "
|
|
|
|
|
"in the built-in variant."
|
|
|
|
|
"<p>When \"Try Both\" is selected, clangd will be employed only if the built-in variant "
|
|
|
|
|
"does not find anything.");
|
2023-01-11 20:43:10 +01:00
|
|
|
const QString workerThreadsToolTip = Tr::tr(
|
2022-09-01 16:12:51 +02:00
|
|
|
"Number of worker threads used by clangd. Background indexing also uses this many "
|
|
|
|
|
"worker threads.");
|
2023-01-11 20:43:10 +01:00
|
|
|
const QString autoIncludeToolTip = Tr::tr(
|
2022-09-01 16:12:51 +02:00
|
|
|
"Controls whether clangd may insert header files as part of symbol completion.");
|
2023-01-11 20:43:10 +01:00
|
|
|
const QString documentUpdateToolTip = Tr::tr(
|
2022-09-01 16:12:51 +02:00
|
|
|
"Defines the amount of time Qt Creator waits before sending document changes to the "
|
|
|
|
|
"server.\n"
|
|
|
|
|
"If the document changes again while waiting, this timeout resets.");
|
2023-01-11 20:43:10 +01:00
|
|
|
const QString sizeThresholdToolTip = Tr::tr(
|
2022-09-01 16:12:51 +02:00
|
|
|
"Files greater than this will not be opened as documents in clangd.\n"
|
|
|
|
|
"The built-in code model will handle highlighting, completion and so on.");
|
2023-01-11 20:43:10 +01:00
|
|
|
const QString completionResultToolTip = Tr::tr(
|
2022-09-01 16:12:51 +02:00
|
|
|
"The maximum number of completion results returned by clangd.");
|
|
|
|
|
|
2023-01-11 20:43:10 +01:00
|
|
|
d->useClangdCheckBox.setText(Tr::tr("Use clangd"));
|
2021-06-28 14:55:54 +02:00
|
|
|
d->useClangdCheckBox.setChecked(settings.useClangd());
|
|
|
|
|
d->clangdChooser.setExpectedKind(Utils::PathChooser::ExistingCommand);
|
|
|
|
|
d->clangdChooser.setFilePath(settings.clangdFilePath());
|
2022-11-22 09:00:11 +01:00
|
|
|
d->clangdChooser.setAllowPathFromDevice(true);
|
2021-06-28 14:55:54 +02:00
|
|
|
d->clangdChooser.setEnabled(d->useClangdCheckBox.isChecked());
|
2023-04-04 20:13:09 +02:00
|
|
|
d->clangdChooser.setCommandVersionArguments({"--version"});
|
2022-09-21 11:17:07 +02:00
|
|
|
using Priority = ClangdSettings::IndexingPriority;
|
|
|
|
|
for (Priority prio : {Priority::Off, Priority::Background, Priority::Low, Priority::Normal}) {
|
|
|
|
|
d->indexingComboBox.addItem(ClangdSettings::priorityToDisplayString(prio), int(prio));
|
|
|
|
|
if (prio == settings.indexingPriority())
|
|
|
|
|
d->indexingComboBox.setCurrentIndex(d->indexingComboBox.count() - 1);
|
|
|
|
|
}
|
|
|
|
|
d->indexingComboBox.setToolTip(indexingToolTip);
|
2023-05-17 13:45:56 +02:00
|
|
|
using SwitchMode = ClangdSettings::HeaderSourceSwitchMode;
|
|
|
|
|
for (SwitchMode mode : {SwitchMode::BuiltinOnly, SwitchMode::ClangdOnly, SwitchMode::Both}) {
|
|
|
|
|
d->headerSourceSwitchComboBox.addItem(
|
|
|
|
|
ClangdSettings::headerSourceSwitchModeToDisplayString(mode), int(mode));
|
|
|
|
|
if (mode == settings.headerSourceSwitchMode())
|
|
|
|
|
d->headerSourceSwitchComboBox.setCurrentIndex(
|
|
|
|
|
d->headerSourceSwitchComboBox.count() - 1);
|
|
|
|
|
}
|
|
|
|
|
d->headerSourceSwitchComboBox.setToolTip(headerSourceSwitchToolTip);
|
2023-01-11 20:43:10 +01:00
|
|
|
d->autoIncludeHeadersCheckBox.setText(Tr::tr("Insert header files on completion"));
|
2021-10-27 11:03:42 +02:00
|
|
|
d->autoIncludeHeadersCheckBox.setChecked(settings.autoIncludeHeaders());
|
2022-09-01 16:12:51 +02:00
|
|
|
d->autoIncludeHeadersCheckBox.setToolTip(autoIncludeToolTip);
|
2021-06-28 14:55:54 +02:00
|
|
|
d->threadLimitSpinBox.setValue(settings.workerThreadLimit());
|
|
|
|
|
d->threadLimitSpinBox.setSpecialValueText("Automatic");
|
2022-09-01 16:12:51 +02:00
|
|
|
d->threadLimitSpinBox.setToolTip(workerThreadsToolTip);
|
2021-08-12 12:00:58 +02:00
|
|
|
d->documentUpdateThreshold.setMinimum(50);
|
|
|
|
|
d->documentUpdateThreshold.setMaximum(10000);
|
|
|
|
|
d->documentUpdateThreshold.setValue(settings.documentUpdateThreshold());
|
|
|
|
|
d->documentUpdateThreshold.setSingleStep(100);
|
|
|
|
|
d->documentUpdateThreshold.setSuffix(" ms");
|
2022-09-01 16:12:51 +02:00
|
|
|
d->documentUpdateThreshold.setToolTip(documentUpdateToolTip);
|
2023-01-11 20:43:10 +01:00
|
|
|
d->sizeThresholdCheckBox.setText(Tr::tr("Ignore files greater than"));
|
2022-03-29 15:47:10 +02:00
|
|
|
d->sizeThresholdCheckBox.setChecked(settings.sizeThresholdEnabled());
|
2022-09-01 16:12:51 +02:00
|
|
|
d->sizeThresholdCheckBox.setToolTip(sizeThresholdToolTip);
|
2022-03-29 15:47:10 +02:00
|
|
|
d->sizeThresholdSpinBox.setMinimum(1);
|
|
|
|
|
d->sizeThresholdSpinBox.setMaximum(std::numeric_limits<int>::max());
|
|
|
|
|
d->sizeThresholdSpinBox.setSuffix(" KB");
|
|
|
|
|
d->sizeThresholdSpinBox.setValue(settings.sizeThresholdInKb());
|
2022-09-01 16:12:51 +02:00
|
|
|
d->sizeThresholdSpinBox.setToolTip(sizeThresholdToolTip);
|
2021-06-28 14:55:54 +02:00
|
|
|
|
2023-01-11 20:43:10 +01:00
|
|
|
const auto completionResultsLabel = new QLabel(Tr::tr("Completion results:"));
|
2022-09-01 16:12:51 +02:00
|
|
|
completionResultsLabel->setToolTip(completionResultToolTip);
|
2022-07-25 17:04:23 +02:00
|
|
|
d->completionResults.setMinimum(0);
|
|
|
|
|
d->completionResults.setMaximum(std::numeric_limits<int>::max());
|
|
|
|
|
d->completionResults.setValue(settings.completionResults());
|
2022-09-01 16:12:51 +02:00
|
|
|
d->completionResults.setToolTip(completionResultToolTip);
|
2023-01-11 20:43:10 +01:00
|
|
|
d->completionResults.setSpecialValueText(Tr::tr("No limit"));
|
2022-07-25 17:04:23 +02:00
|
|
|
|
2021-06-28 14:55:54 +02:00
|
|
|
const auto layout = new QVBoxLayout(this);
|
2021-12-01 20:31:08 +01:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
2021-06-28 14:55:54 +02:00
|
|
|
layout->addWidget(&d->useClangdCheckBox);
|
2022-09-08 16:36:27 +03:00
|
|
|
|
2021-06-28 14:55:54 +02:00
|
|
|
const auto formLayout = new QFormLayout;
|
2023-01-11 20:43:10 +01:00
|
|
|
const auto chooserLabel = new QLabel(Tr::tr("Path to executable:"));
|
2021-06-28 14:55:54 +02:00
|
|
|
formLayout->addRow(chooserLabel, &d->clangdChooser);
|
2021-10-07 16:15:08 +02:00
|
|
|
formLayout->addRow(QString(), &d->versionWarningLabel);
|
2022-09-21 11:17:07 +02:00
|
|
|
|
|
|
|
|
const auto indexingPriorityLayout = new QHBoxLayout;
|
|
|
|
|
indexingPriorityLayout->addWidget(&d->indexingComboBox);
|
|
|
|
|
indexingPriorityLayout->addStretch(1);
|
2023-01-11 20:43:10 +01:00
|
|
|
const auto indexingPriorityLabel = new QLabel(Tr::tr("Background indexing:"));
|
2022-09-21 11:17:07 +02:00
|
|
|
indexingPriorityLabel->setToolTip(indexingToolTip);
|
|
|
|
|
formLayout->addRow(indexingPriorityLabel, indexingPriorityLayout);
|
|
|
|
|
|
2023-05-17 13:45:56 +02:00
|
|
|
const auto headerSourceSwitchLayout = new QHBoxLayout;
|
|
|
|
|
headerSourceSwitchLayout->addWidget(&d->headerSourceSwitchComboBox);
|
|
|
|
|
headerSourceSwitchLayout->addStretch(1);
|
|
|
|
|
const auto headerSourceSwitchLabel = new QLabel(Tr::tr("Header/source switch mode:"));
|
|
|
|
|
headerSourceSwitchLabel->setToolTip(headerSourceSwitchToolTip);
|
|
|
|
|
formLayout->addRow(headerSourceSwitchLabel, headerSourceSwitchLayout);
|
|
|
|
|
|
2021-06-28 14:55:54 +02:00
|
|
|
const auto threadLimitLayout = new QHBoxLayout;
|
|
|
|
|
threadLimitLayout->addWidget(&d->threadLimitSpinBox);
|
|
|
|
|
threadLimitLayout->addStretch(1);
|
2023-01-11 20:43:10 +01:00
|
|
|
const auto threadLimitLabel = new QLabel(Tr::tr("Worker thread count:"));
|
2022-09-01 16:12:51 +02:00
|
|
|
threadLimitLabel->setToolTip(workerThreadsToolTip);
|
2021-06-28 14:55:54 +02:00
|
|
|
formLayout->addRow(threadLimitLabel, threadLimitLayout);
|
2022-07-25 17:04:23 +02:00
|
|
|
|
2022-09-08 16:36:27 +03:00
|
|
|
formLayout->addRow(QString(), &d->autoIncludeHeadersCheckBox);
|
2022-07-25 17:04:23 +02:00
|
|
|
const auto limitResultsLayout = new QHBoxLayout;
|
|
|
|
|
limitResultsLayout->addWidget(&d->completionResults);
|
|
|
|
|
limitResultsLayout->addStretch(1);
|
|
|
|
|
formLayout->addRow(completionResultsLabel, limitResultsLayout);
|
|
|
|
|
|
2022-09-01 16:12:51 +02:00
|
|
|
const auto documentUpdateThresholdLayout = new QHBoxLayout;
|
|
|
|
|
documentUpdateThresholdLayout->addWidget(&d->documentUpdateThreshold);
|
|
|
|
|
documentUpdateThresholdLayout->addStretch(1);
|
2023-01-11 20:43:10 +01:00
|
|
|
const auto documentUpdateThresholdLabel = new QLabel(Tr::tr("Document update threshold:"));
|
2022-09-01 16:12:51 +02:00
|
|
|
documentUpdateThresholdLabel->setToolTip(documentUpdateToolTip);
|
|
|
|
|
formLayout->addRow(documentUpdateThresholdLabel, documentUpdateThresholdLayout);
|
2022-03-29 15:47:10 +02:00
|
|
|
const auto sizeThresholdLayout = new QHBoxLayout;
|
|
|
|
|
sizeThresholdLayout->addWidget(&d->sizeThresholdSpinBox);
|
|
|
|
|
sizeThresholdLayout->addStretch(1);
|
|
|
|
|
formLayout->addRow(&d->sizeThresholdCheckBox, sizeThresholdLayout);
|
2022-09-01 16:12:51 +02:00
|
|
|
|
2022-05-19 14:48:09 +02:00
|
|
|
d->configSelectionWidget = new ClangDiagnosticConfigsSelectionWidget(formLayout);
|
|
|
|
|
d->configSelectionWidget->refresh(
|
|
|
|
|
diagnosticConfigsModel(settings.customDiagnosticConfigs()),
|
|
|
|
|
settings.diagnosticConfigId(),
|
|
|
|
|
[](const ClangDiagnosticConfigs &configs, const Utils::Id &configToSelect) {
|
|
|
|
|
return new CppEditor::ClangDiagnosticConfigsWidget(configs, configToSelect);
|
|
|
|
|
});
|
2021-11-23 17:04:13 +01:00
|
|
|
|
2022-05-19 14:48:09 +02:00
|
|
|
layout->addLayout(formLayout);
|
2021-11-23 17:04:13 +01:00
|
|
|
if (!isForProject) {
|
|
|
|
|
d->sessionsModel.setStringList(settingsData.sessionsWithOneClangd);
|
|
|
|
|
d->sessionsModel.sort(0);
|
2023-01-11 20:43:10 +01:00
|
|
|
d->sessionsGroupBox = new QGroupBox(Tr::tr("Sessions with a single clangd instance"));
|
2021-11-23 17:04:13 +01:00
|
|
|
const auto sessionsView = new Utils::ListView;
|
|
|
|
|
sessionsView->setModel(&d->sessionsModel);
|
|
|
|
|
sessionsView->setToolTip(
|
2023-01-11 20:43:10 +01:00
|
|
|
Tr::tr("By default, Qt Creator runs one clangd process per project.\n"
|
2021-11-23 17:04:13 +01:00
|
|
|
"If you have sessions with tightly coupled projects that should be\n"
|
|
|
|
|
"managed by the same clangd process, add them here."));
|
|
|
|
|
const auto outerSessionsLayout = new QHBoxLayout;
|
|
|
|
|
const auto innerSessionsLayout = new QHBoxLayout(d->sessionsGroupBox);
|
|
|
|
|
const auto buttonsLayout = new QVBoxLayout;
|
2023-01-11 20:43:10 +01:00
|
|
|
const auto addButton = new QPushButton(Tr::tr("Add ..."));
|
|
|
|
|
const auto removeButton = new QPushButton(Tr::tr("Remove"));
|
2021-11-23 17:04:13 +01:00
|
|
|
buttonsLayout->addWidget(addButton);
|
|
|
|
|
buttonsLayout->addWidget(removeButton);
|
|
|
|
|
buttonsLayout->addStretch(1);
|
|
|
|
|
innerSessionsLayout->addWidget(sessionsView);
|
|
|
|
|
innerSessionsLayout->addLayout(buttonsLayout);
|
|
|
|
|
outerSessionsLayout->addWidget(d->sessionsGroupBox);
|
|
|
|
|
outerSessionsLayout->addStretch(1);
|
2022-08-24 11:16:20 +02:00
|
|
|
|
|
|
|
|
const auto separator = new QFrame;
|
|
|
|
|
separator->setFrameShape(QFrame::HLine);
|
|
|
|
|
layout->addWidget(separator);
|
2021-11-23 17:04:13 +01:00
|
|
|
layout->addLayout(outerSessionsLayout);
|
|
|
|
|
|
|
|
|
|
const auto updateRemoveButtonState = [removeButton, sessionsView] {
|
|
|
|
|
removeButton->setEnabled(sessionsView->selectionModel()->hasSelection());
|
|
|
|
|
};
|
|
|
|
|
connect(sessionsView->selectionModel(), &QItemSelectionModel::selectionChanged,
|
|
|
|
|
this, updateRemoveButtonState);
|
|
|
|
|
updateRemoveButtonState();
|
|
|
|
|
connect(removeButton, &QPushButton::clicked, this, [this, sessionsView] {
|
|
|
|
|
const QItemSelection selection = sessionsView->selectionModel()->selection();
|
|
|
|
|
QTC_ASSERT(!selection.isEmpty(), return);
|
|
|
|
|
d->sessionsModel.removeRow(selection.indexes().first().row());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(addButton, &QPushButton::clicked, this, [this, sessionsView] {
|
|
|
|
|
QInputDialog dlg(sessionsView);
|
2023-05-23 15:05:38 +02:00
|
|
|
QStringList sessions = Core::SessionManager::sessions();
|
2021-11-23 17:04:13 +01:00
|
|
|
QStringList currentSessions = d->sessionsModel.stringList();
|
2022-10-07 14:46:06 +02:00
|
|
|
for (const QString &s : std::as_const(currentSessions))
|
2021-11-23 17:04:13 +01:00
|
|
|
sessions.removeOne(s);
|
|
|
|
|
if (sessions.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
sessions.sort();
|
2023-01-11 20:43:10 +01:00
|
|
|
dlg.setLabelText(Tr::tr("Choose a session:"));
|
2021-11-23 17:04:13 +01:00
|
|
|
dlg.setComboBoxItems(sessions);
|
|
|
|
|
if (dlg.exec() == QDialog::Accepted) {
|
|
|
|
|
currentSessions << dlg.textValue();
|
|
|
|
|
d->sessionsModel.setStringList(currentSessions);
|
|
|
|
|
d->sessionsModel.sort(0);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-05-16 16:40:29 +02:00
|
|
|
|
|
|
|
|
const auto configFilesHelpLabel = new QLabel;
|
2023-01-11 20:43:10 +01:00
|
|
|
configFilesHelpLabel->setText(Tr::tr("Additional settings are available via "
|
2022-05-16 16:40:29 +02:00
|
|
|
"<a href=\"https://clangd.llvm.org/config\"> clangd configuration files</a>.<br>"
|
2022-07-22 16:13:18 +02:00
|
|
|
"User-specific settings go <a href=\"%1\">here</a>, "
|
|
|
|
|
"project-specific settings can be configured by putting a .clangd file into "
|
2022-05-16 16:40:29 +02:00
|
|
|
"the project source tree.")
|
|
|
|
|
.arg(ClangdSettings::clangdUserConfigFilePath().toUserOutput()));
|
2022-09-08 16:34:52 +03:00
|
|
|
configFilesHelpLabel->setWordWrap(true);
|
2022-05-16 16:40:29 +02:00
|
|
|
connect(configFilesHelpLabel, &QLabel::linkHovered, configFilesHelpLabel, &QLabel::setToolTip);
|
|
|
|
|
connect(configFilesHelpLabel, &QLabel::linkActivated, [](const QString &link) {
|
|
|
|
|
if (link.startsWith("https"))
|
|
|
|
|
QDesktopServices::openUrl(link);
|
|
|
|
|
else
|
|
|
|
|
Core::EditorManager::openEditor(Utils::FilePath::fromString(link));
|
|
|
|
|
});
|
2023-04-25 10:15:07 +02:00
|
|
|
layout->addWidget(Layouting::createHr());
|
2022-05-16 16:40:29 +02:00
|
|
|
layout->addWidget(configFilesHelpLabel);
|
|
|
|
|
|
2021-06-28 14:55:54 +02:00
|
|
|
layout->addStretch(1);
|
|
|
|
|
|
2021-11-02 16:42:48 +01:00
|
|
|
static const auto setWidgetsEnabled = [](QLayout *layout, bool enabled, const auto &f) -> void {
|
|
|
|
|
for (int i = 0; i < layout->count(); ++i) {
|
|
|
|
|
if (QWidget * const w = layout->itemAt(i)->widget())
|
|
|
|
|
w->setEnabled(enabled);
|
|
|
|
|
else if (QLayout * const l = layout->itemAt(i)->layout())
|
|
|
|
|
f(l, enabled, f);
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-11-23 17:04:13 +01:00
|
|
|
const auto toggleEnabled = [this, formLayout](const bool checked) {
|
2021-11-02 16:42:48 +01:00
|
|
|
setWidgetsEnabled(formLayout, checked, setWidgetsEnabled);
|
2021-11-23 17:04:13 +01:00
|
|
|
if (d->sessionsGroupBox)
|
|
|
|
|
d->sessionsGroupBox->setEnabled(checked);
|
2021-06-28 14:55:54 +02:00
|
|
|
};
|
|
|
|
|
connect(&d->useClangdCheckBox, &QCheckBox::toggled, toggleEnabled);
|
|
|
|
|
toggleEnabled(d->useClangdCheckBox.isChecked());
|
|
|
|
|
d->threadLimitSpinBox.setEnabled(d->useClangdCheckBox.isChecked());
|
2021-10-07 16:15:08 +02:00
|
|
|
|
|
|
|
|
d->versionWarningLabel.setType(Utils::InfoLabel::Warning);
|
|
|
|
|
const auto updateWarningLabel = [this] {
|
|
|
|
|
class WarningLabelSetter {
|
|
|
|
|
public:
|
|
|
|
|
WarningLabelSetter(QLabel &label) : m_label(label) { m_label.clear(); }
|
|
|
|
|
~WarningLabelSetter() { m_label.setVisible(!m_label.text().isEmpty()); }
|
|
|
|
|
void setWarning(const QString &text) { m_label.setText(text); }
|
|
|
|
|
private:
|
|
|
|
|
QLabel &m_label;
|
|
|
|
|
};
|
|
|
|
|
WarningLabelSetter labelSetter(d->versionWarningLabel);
|
|
|
|
|
|
|
|
|
|
if (!d->clangdChooser.isValid())
|
|
|
|
|
return;
|
|
|
|
|
const Utils::FilePath clangdPath = d->clangdChooser.filePath();
|
2023-01-10 10:21:56 +01:00
|
|
|
QString errorMessage;
|
|
|
|
|
if (!Utils::checkClangdVersion(clangdPath, &errorMessage))
|
|
|
|
|
labelSetter.setWarning(errorMessage);
|
2021-10-07 16:15:08 +02:00
|
|
|
};
|
2022-09-02 11:49:36 +02:00
|
|
|
connect(&d->clangdChooser, &Utils::PathChooser::textChanged, this, updateWarningLabel);
|
2023-08-22 15:27:34 +02:00
|
|
|
connect(&d->clangdChooser, &Utils::PathChooser::validChanged, this, updateWarningLabel);
|
2021-10-07 16:15:08 +02:00
|
|
|
updateWarningLabel();
|
2021-06-28 14:55:54 +02:00
|
|
|
|
|
|
|
|
connect(&d->useClangdCheckBox, &QCheckBox::toggled,
|
|
|
|
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
2022-09-21 11:17:07 +02:00
|
|
|
connect(&d->indexingComboBox, &QComboBox::currentIndexChanged,
|
2021-06-28 14:55:54 +02:00
|
|
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
2023-05-17 13:45:56 +02:00
|
|
|
connect(&d->headerSourceSwitchComboBox, &QComboBox::currentIndexChanged,
|
|
|
|
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
2021-10-27 11:03:42 +02:00
|
|
|
connect(&d->autoIncludeHeadersCheckBox, &QCheckBox::toggled,
|
|
|
|
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
2022-07-19 23:36:11 +02:00
|
|
|
connect(&d->threadLimitSpinBox, &QSpinBox::valueChanged,
|
2021-06-28 14:55:54 +02:00
|
|
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
2022-03-29 15:47:10 +02:00
|
|
|
connect(&d->sizeThresholdCheckBox, &QCheckBox::toggled,
|
|
|
|
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
2022-07-19 23:36:11 +02:00
|
|
|
connect(&d->sizeThresholdSpinBox, &QSpinBox::valueChanged,
|
2022-03-29 15:47:10 +02:00
|
|
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
2022-07-19 23:36:11 +02:00
|
|
|
connect(&d->documentUpdateThreshold, &QSpinBox::valueChanged,
|
2022-04-21 15:24:40 +02:00
|
|
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
2022-09-02 11:49:36 +02:00
|
|
|
connect(&d->clangdChooser, &Utils::PathChooser::textChanged,
|
2021-06-28 14:55:54 +02:00
|
|
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
2022-05-19 14:48:09 +02:00
|
|
|
connect(d->configSelectionWidget, &ClangDiagnosticConfigsSelectionWidget::changed,
|
|
|
|
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
2022-08-04 13:57:58 +02:00
|
|
|
connect(&d->completionResults, &QSpinBox::valueChanged,
|
|
|
|
|
this, &ClangdSettingsWidget::settingsDataChanged);
|
2021-06-28 14:55:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangdSettingsWidget::~ClangdSettingsWidget()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangdSettings::Data ClangdSettingsWidget::settingsData() const
|
|
|
|
|
{
|
|
|
|
|
ClangdSettings::Data data;
|
|
|
|
|
data.useClangd = d->useClangdCheckBox.isChecked();
|
|
|
|
|
data.executableFilePath = d->clangdChooser.filePath();
|
2022-09-21 11:17:07 +02:00
|
|
|
data.indexingPriority = ClangdSettings::IndexingPriority(
|
|
|
|
|
d->indexingComboBox.currentData().toInt());
|
2023-05-17 13:45:56 +02:00
|
|
|
data.headerSourceSwitchMode = ClangdSettings::HeaderSourceSwitchMode(
|
|
|
|
|
d->headerSourceSwitchComboBox.currentData().toInt());
|
2021-10-27 11:03:42 +02:00
|
|
|
data.autoIncludeHeaders = d->autoIncludeHeadersCheckBox.isChecked();
|
2021-06-28 14:55:54 +02:00
|
|
|
data.workerThreadLimit = d->threadLimitSpinBox.value();
|
2021-08-12 12:00:58 +02:00
|
|
|
data.documentUpdateThreshold = d->documentUpdateThreshold.value();
|
2022-03-29 15:47:10 +02:00
|
|
|
data.sizeThresholdEnabled = d->sizeThresholdCheckBox.isChecked();
|
|
|
|
|
data.sizeThresholdInKb = d->sizeThresholdSpinBox.value();
|
2021-11-23 17:04:13 +01:00
|
|
|
data.sessionsWithOneClangd = d->sessionsModel.stringList();
|
2022-05-19 14:48:09 +02:00
|
|
|
data.customDiagnosticConfigs = d->configSelectionWidget->customConfigs();
|
|
|
|
|
data.diagnosticConfigId = d->configSelectionWidget->currentConfigId();
|
2022-08-04 13:57:58 +02:00
|
|
|
data.completionResults = d->completionResults.value();
|
2021-06-28 14:55:54 +02:00
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ClangdSettingsPageWidget final : public Core::IOptionsPageWidget
|
2021-06-25 16:50:52 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2021-11-23 17:04:13 +01:00
|
|
|
ClangdSettingsPageWidget() : m_widget(ClangdSettings::instance().data(), false)
|
2021-06-25 16:50:52 +02:00
|
|
|
{
|
|
|
|
|
const auto layout = new QVBoxLayout(this);
|
2021-06-28 14:55:54 +02:00
|
|
|
layout->addWidget(&m_widget);
|
2021-06-25 16:50:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2021-06-28 14:55:54 +02:00
|
|
|
void apply() final { ClangdSettings::instance().setData(m_widget.settingsData()); }
|
2021-06-25 16:50:52 +02:00
|
|
|
|
2021-06-28 14:55:54 +02:00
|
|
|
ClangdSettingsWidget m_widget;
|
2021-06-25 16:50:52 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ClangdSettingsPage::ClangdSettingsPage()
|
|
|
|
|
{
|
2021-11-23 17:04:13 +01:00
|
|
|
setId(Constants::CPP_CLANGD_SETTINGS_ID);
|
2023-01-11 20:43:10 +01:00
|
|
|
setDisplayName(Tr::tr("Clangd"));
|
2021-06-25 16:50:52 +02:00
|
|
|
setCategory(Constants::CPP_SETTINGS_CATEGORY);
|
2021-06-28 14:55:54 +02:00
|
|
|
setWidgetCreator([] { return new ClangdSettingsPageWidget; });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ClangdProjectSettingsWidget::Private
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-11-23 17:04:13 +01:00
|
|
|
Private(const ClangdProjectSettings &s) : settings(s), widget(s.settings(), true) {}
|
2021-06-28 14:55:54 +02:00
|
|
|
|
|
|
|
|
ClangdProjectSettings settings;
|
|
|
|
|
ClangdSettingsWidget widget;
|
|
|
|
|
QCheckBox useGlobalSettingsCheckBox;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ClangdProjectSettingsWidget::ClangdProjectSettingsWidget(const ClangdProjectSettings &settings)
|
|
|
|
|
: d(new Private(settings))
|
|
|
|
|
{
|
2022-04-14 15:51:18 +02:00
|
|
|
setGlobalSettingsId(Constants::CPP_CLANGD_SETTINGS_ID);
|
2021-06-28 14:55:54 +02:00
|
|
|
const auto layout = new QVBoxLayout(this);
|
2021-12-01 20:31:08 +01:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
2021-06-28 14:55:54 +02:00
|
|
|
layout->addWidget(&d->widget);
|
|
|
|
|
|
2021-11-23 17:04:13 +01:00
|
|
|
const auto updateGlobalSettingsCheckBox = [this] {
|
|
|
|
|
if (ClangdSettings::instance().granularity() == ClangdSettings::Granularity::Session) {
|
2022-04-14 15:51:18 +02:00
|
|
|
setUseGlobalSettingsCheckBoxEnabled(false);
|
|
|
|
|
setUseGlobalSettings(true);
|
2021-11-23 17:04:13 +01:00
|
|
|
} else {
|
2022-04-14 15:51:18 +02:00
|
|
|
setUseGlobalSettingsCheckBoxEnabled(true);
|
|
|
|
|
setUseGlobalSettings(d->settings.useGlobalSettings());
|
2021-11-23 17:04:13 +01:00
|
|
|
}
|
2022-04-14 15:51:18 +02:00
|
|
|
d->widget.setEnabled(!useGlobalSettings());
|
2021-11-23 17:04:13 +01:00
|
|
|
};
|
2022-04-14 15:51:18 +02:00
|
|
|
|
2021-11-23 17:04:13 +01:00
|
|
|
updateGlobalSettingsCheckBox();
|
|
|
|
|
connect(&ClangdSettings::instance(), &ClangdSettings::changed,
|
|
|
|
|
this, updateGlobalSettingsCheckBox);
|
|
|
|
|
|
2022-04-14 15:51:18 +02:00
|
|
|
connect(this, &ProjectSettingsWidget::useGlobalSettingsChanged, this,
|
|
|
|
|
[this](bool checked) {
|
|
|
|
|
d->widget.setEnabled(!checked);
|
|
|
|
|
d->settings.setUseGlobalSettings(checked);
|
|
|
|
|
if (!checked)
|
|
|
|
|
d->settings.setSettings(d->widget.settingsData());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(&d->widget, &ClangdSettingsWidget::settingsDataChanged, this, [this] {
|
2021-06-28 14:55:54 +02:00
|
|
|
d->settings.setSettings(d->widget.settingsData());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangdProjectSettingsWidget::~ClangdProjectSettingsWidget()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
2021-06-25 16:50:52 +02:00
|
|
|
}
|
|
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
} // CppEditor::Internal
|