2013-09-06 13:14:15 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-09-06 13:14:15 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2013-09-06 13:14:15 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
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"
|
2019-01-10 11:38:06 +01:00
|
|
|
#include "cpptoolsreuse.h"
|
2013-09-06 13:14:15 +02:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
2022-07-12 18:21:44 +02:00
|
|
|
|
2021-11-23 17:04:13 +01:00
|
|
|
#include <projectexplorer/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-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>
|
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
|
|
|
{
|
2021-08-30 10:58:08 +02:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(CppEditor::Internal::CppCodeModelSettingsWidget)
|
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;
|
|
|
|
|
QCheckBox *m_skipIndexingBigFilesCheckBox;
|
|
|
|
|
QSpinBox *m_bigFilesLimitSpinBox;
|
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
|
|
|
|
|
= new QCheckBox(tr("Interpret ambiguous headers as C headers"));
|
2020-01-17 15:15:24 +01:00
|
|
|
|
2022-07-12 18:21:44 +02:00
|
|
|
m_skipIndexingBigFilesCheckBox = new QCheckBox(tr("Do not index files greater than"));
|
|
|
|
|
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;
|
|
|
|
|
m_bigFilesLimitSpinBox->setSuffix(tr("MB"));
|
|
|
|
|
m_bigFilesLimitSpinBox->setRange(1, 500);
|
|
|
|
|
m_bigFilesLimitSpinBox->setValue(m_settings->indexerFileSizeLimitInMb());
|
2013-09-06 13:14:15 +02:00
|
|
|
|
2022-07-12 18:21:44 +02:00
|
|
|
m_ignorePchCheckBox = new QCheckBox(tr("Ignore precompiled headers"));
|
|
|
|
|
m_ignorePchCheckBox->setToolTip(tr(
|
|
|
|
|
"<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>"));
|
|
|
|
|
|
|
|
|
|
m_interpretAmbiguousHeadersAsCHeaders->setChecked(
|
|
|
|
|
m_settings->interpretAmbigiousHeadersAsCHeaders());
|
|
|
|
|
|
|
|
|
|
m_ignorePchCheckBox->setChecked(m_settings->pchUsage() == CppCodeModelSettings::PchUse_None);
|
|
|
|
|
|
|
|
|
|
using namespace Utils::Layouting;
|
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
Group {
|
|
|
|
|
Title(tr("General")),
|
|
|
|
|
Column {
|
|
|
|
|
m_interpretAmbiguousHeadersAsCHeaders,
|
|
|
|
|
m_ignorePchCheckBox,
|
2022-07-22 18:54:04 +02:00
|
|
|
Row { m_skipIndexingBigFilesCheckBox, m_bigFilesLimitSpinBox, st },
|
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-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);
|
2020-01-17 15:15:24 +01:00
|
|
|
setDisplayName(CppCodeModelSettingsWidget::tr("Code Model"));
|
2013-09-06 13:14:15 +02:00
|
|
|
setCategory(Constants::CPP_SETTINGS_CATEGORY);
|
2021-08-30 10:58:08 +02:00
|
|
|
setDisplayCategory(QCoreApplication::translate("CppEditor", "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;
|
|
|
|
|
QCheckBox indexingCheckBox;
|
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);
|
2022-01-27 12:27:45 +01:00
|
|
|
d->useClangdCheckBox.setText(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());
|
|
|
|
|
d->clangdChooser.setEnabled(d->useClangdCheckBox.isChecked());
|
|
|
|
|
d->indexingCheckBox.setChecked(settings.indexingEnabled());
|
|
|
|
|
d->indexingCheckBox.setToolTip(tr(
|
|
|
|
|
"If background indexing is enabled, global symbol searches will yield\n"
|
|
|
|
|
"more accurate results, at the cost of additional CPU load when\n"
|
|
|
|
|
"the project is first opened."));
|
2021-10-27 11:03:42 +02:00
|
|
|
d->autoIncludeHeadersCheckBox.setChecked(settings.autoIncludeHeaders());
|
|
|
|
|
d->autoIncludeHeadersCheckBox.setToolTip(tr(
|
|
|
|
|
"Controls whether clangd may insert header files as part of symbol completion."));
|
2021-06-28 14:55:54 +02:00
|
|
|
d->threadLimitSpinBox.setValue(settings.workerThreadLimit());
|
|
|
|
|
d->threadLimitSpinBox.setSpecialValueText("Automatic");
|
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");
|
|
|
|
|
d->documentUpdateThreshold.setToolTip(
|
|
|
|
|
tr("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.\n"));
|
2022-03-29 15:47:10 +02:00
|
|
|
d->sizeThresholdCheckBox.setText(tr("Ignore files greater than"));
|
|
|
|
|
d->sizeThresholdCheckBox.setChecked(settings.sizeThresholdEnabled());
|
|
|
|
|
d->sizeThresholdSpinBox.setMinimum(1);
|
|
|
|
|
d->sizeThresholdSpinBox.setMaximum(std::numeric_limits<int>::max());
|
|
|
|
|
d->sizeThresholdSpinBox.setSuffix(" KB");
|
|
|
|
|
d->sizeThresholdSpinBox.setValue(settings.sizeThresholdInKb());
|
|
|
|
|
d->sizeThresholdSpinBox.setToolTip(tr(
|
|
|
|
|
"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."));
|
2021-06-28 14:55:54 +02:00
|
|
|
|
2022-07-25 17:04:23 +02:00
|
|
|
const auto completionResultsLabel = new QLabel(tr("Completion results:"));
|
|
|
|
|
d->completionResults.setMinimum(0);
|
|
|
|
|
d->completionResults.setMaximum(std::numeric_limits<int>::max());
|
|
|
|
|
d->completionResults.setValue(settings.completionResults());
|
|
|
|
|
d->completionResults.setToolTip(tr("The maximum number of completion results returned by clangd"));
|
|
|
|
|
d->completionResults.setSpecialValueText(tr("No limit"));
|
|
|
|
|
|
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);
|
|
|
|
|
const auto formLayout = new QFormLayout;
|
|
|
|
|
const auto chooserLabel = new QLabel(tr("Path to executable:"));
|
|
|
|
|
formLayout->addRow(chooserLabel, &d->clangdChooser);
|
2021-10-07 16:15:08 +02:00
|
|
|
formLayout->addRow(QString(), &d->versionWarningLabel);
|
2021-06-28 14:55:54 +02:00
|
|
|
const auto indexingLabel = new QLabel(tr("Enable background indexing:"));
|
|
|
|
|
formLayout->addRow(indexingLabel, &d->indexingCheckBox);
|
2021-10-27 11:03:42 +02:00
|
|
|
const auto autoIncludeHeadersLabel = new QLabel(tr("Insert header files on completion:"));
|
|
|
|
|
formLayout->addRow(autoIncludeHeadersLabel, &d->autoIncludeHeadersCheckBox);
|
2021-06-28 14:55:54 +02:00
|
|
|
const auto threadLimitLayout = new QHBoxLayout;
|
|
|
|
|
threadLimitLayout->addWidget(&d->threadLimitSpinBox);
|
|
|
|
|
threadLimitLayout->addStretch(1);
|
2021-08-12 12:00:58 +02:00
|
|
|
const auto threadLimitLabel = new QLabel(tr("Worker thread count:"));
|
2021-06-28 14:55:54 +02:00
|
|
|
formLayout->addRow(threadLimitLabel, threadLimitLayout);
|
2021-08-12 12:00:58 +02:00
|
|
|
const auto documentUpdateThresholdLayout = new QHBoxLayout;
|
|
|
|
|
documentUpdateThresholdLayout->addWidget(&d->documentUpdateThreshold);
|
|
|
|
|
documentUpdateThresholdLayout->addStretch(1);
|
|
|
|
|
const auto documentUpdateThresholdLabel = new QLabel(tr("Document update threshold:"));
|
|
|
|
|
formLayout->addRow(documentUpdateThresholdLabel, documentUpdateThresholdLayout);
|
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-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-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);
|
|
|
|
|
d->sessionsGroupBox = new QGroupBox(tr("Sessions with a single clangd instance"));
|
|
|
|
|
const auto sessionsView = new Utils::ListView;
|
|
|
|
|
sessionsView->setModel(&d->sessionsModel);
|
|
|
|
|
sessionsView->setToolTip(
|
|
|
|
|
tr("By default, Qt Creator runs one clangd process per project.\n"
|
|
|
|
|
"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;
|
|
|
|
|
const auto addButton = new QPushButton(tr("Add ..."));
|
|
|
|
|
const auto removeButton = new QPushButton(tr("Remove"));
|
|
|
|
|
buttonsLayout->addWidget(addButton);
|
|
|
|
|
buttonsLayout->addWidget(removeButton);
|
|
|
|
|
buttonsLayout->addStretch(1);
|
|
|
|
|
innerSessionsLayout->addWidget(sessionsView);
|
|
|
|
|
innerSessionsLayout->addLayout(buttonsLayout);
|
|
|
|
|
outerSessionsLayout->addWidget(d->sessionsGroupBox);
|
|
|
|
|
outerSessionsLayout->addStretch(1);
|
|
|
|
|
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);
|
|
|
|
|
QStringList sessions = ProjectExplorer::SessionManager::sessions();
|
|
|
|
|
QStringList currentSessions = d->sessionsModel.stringList();
|
|
|
|
|
for (const QString &s : qAsConst(currentSessions))
|
|
|
|
|
sessions.removeOne(s);
|
|
|
|
|
if (sessions.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
sessions.sort();
|
|
|
|
|
dlg.setLabelText(tr("Choose a session:"));
|
|
|
|
|
dlg.setComboBoxItems(sessions);
|
|
|
|
|
if (dlg.exec() == QDialog::Accepted) {
|
|
|
|
|
currentSessions << dlg.textValue();
|
|
|
|
|
d->sessionsModel.setStringList(currentSessions);
|
|
|
|
|
d->sessionsModel.sort(0);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// TODO: Remove once the concept is functional.
|
|
|
|
|
d->sessionsGroupBox->hide();
|
|
|
|
|
}
|
2022-05-16 16:40:29 +02:00
|
|
|
|
|
|
|
|
const auto configFilesHelpLabel = new QLabel;
|
|
|
|
|
configFilesHelpLabel->setText(tr("Additional settings are available via "
|
|
|
|
|
"<a href=\"https://clangd.llvm.org/config\"> clangd configuration files</a>.<br>"
|
|
|
|
|
"General settings go <a href=\"%1\">here</a> "
|
|
|
|
|
"and can be overridden per project by putting a .clangd file into "
|
|
|
|
|
"the project source tree.")
|
|
|
|
|
.arg(ClangdSettings::clangdUserConfigFilePath().toUserOutput()));
|
|
|
|
|
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));
|
|
|
|
|
});
|
|
|
|
|
const auto separator = new QFrame;
|
|
|
|
|
separator->setFrameShape(QFrame::HLine);
|
|
|
|
|
layout->addWidget(separator);
|
|
|
|
|
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();
|
2021-11-01 12:06:38 +01:00
|
|
|
const QVersionNumber clangdVersion = ClangdSettings::clangdVersion(clangdPath);
|
2021-10-07 16:15:08 +02:00
|
|
|
if (clangdVersion.isNull()) {
|
|
|
|
|
labelSetter.setWarning(tr("Failed to retrieve clangd version: "
|
|
|
|
|
"Unexpected clangd output."));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-02 17:18:46 +02:00
|
|
|
if (clangdVersion < QVersionNumber(14)) {
|
2021-11-01 12:06:38 +01:00
|
|
|
labelSetter.setWarning(tr("The clangd version is %1, but %2 or greater is required.")
|
2022-05-02 17:18:46 +02:00
|
|
|
.arg(clangdVersion.toString()).arg(14));
|
2021-10-07 16:15:08 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
2022-06-29 17:21:30 +02:00
|
|
|
connect(&d->clangdChooser, &Utils::PathChooser::filePathChanged, 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);
|
|
|
|
|
connect(&d->indexingCheckBox, &QCheckBox::toggled,
|
|
|
|
|
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-06-29 17:21:30 +02:00
|
|
|
connect(&d->clangdChooser, &Utils::PathChooser::filePathChanged,
|
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);
|
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();
|
|
|
|
|
data.enableIndexing = d->indexingCheckBox.isChecked();
|
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();
|
2021-06-28 14:55:54 +02:00
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ClangdSettingsPageWidget final : public Core::IOptionsPageWidget
|
2021-06-25 16:50:52 +02:00
|
|
|
{
|
2021-08-30 10:58:08 +02:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(CppEditor::Internal::ClangdSettingsWidget)
|
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);
|
2021-06-25 16:50:52 +02:00
|
|
|
setDisplayName(ClangdSettingsWidget::tr("Clangd"));
|
|
|
|
|
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
|