forked from qt-creator/qt-creator
LanguageClient: Add option to hide settings
Change-Id: Iefc9398bdc4ffcf498eb66a702994e9e143beb74 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -160,6 +160,7 @@ local function setupClient()
|
||||
},
|
||||
settings = Settings,
|
||||
startBehavior = "AlwaysOn",
|
||||
showInSettings = false,
|
||||
onStartFailed = function()
|
||||
a.sync(function()
|
||||
if IsTryingToInstall == true then
|
||||
|
@@ -100,7 +100,7 @@ public:
|
||||
|
||||
void reset(const QList<BaseSettings *> &settings);
|
||||
QList<BaseSettings *> settings() const { return m_settings; }
|
||||
int insertSettings(BaseSettings *settings);
|
||||
QModelIndex insertSettings(BaseSettings *settings);
|
||||
void enableSetting(const QString &id, bool enable = true);
|
||||
QList<BaseSettings *> removed() const { return m_removed; }
|
||||
BaseSettings *settingForIndex(const QModelIndex &index) const;
|
||||
@@ -112,6 +112,52 @@ private:
|
||||
QList<BaseSettings *> m_removed;
|
||||
};
|
||||
|
||||
class FilterProxy final : public QSortFilterProxyModel
|
||||
{
|
||||
public:
|
||||
FilterProxy(LanguageClientSettingsModel &sourceModel)
|
||||
: m_settings(sourceModel)
|
||||
{
|
||||
setSourceModel(&sourceModel);
|
||||
}
|
||||
|
||||
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const final
|
||||
{
|
||||
const QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||
const BaseSettings *setting
|
||||
= static_cast<LanguageClientSettingsModel *>(sourceModel())->settingForIndex(index);
|
||||
return setting && setting->m_showInSettings;
|
||||
}
|
||||
|
||||
void reset(QList<BaseSettings *> settings)
|
||||
{
|
||||
m_settings.reset(settings);
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
QModelIndex insertSettings(BaseSettings *settings)
|
||||
{
|
||||
const auto idx = m_settings.insertSettings(settings);
|
||||
invalidateFilter();
|
||||
return mapFromSource(idx);
|
||||
}
|
||||
|
||||
BaseSettings *settingForIndex(const QModelIndex &index) const
|
||||
{
|
||||
return m_settings.settingForIndex(mapToSource(index));
|
||||
}
|
||||
|
||||
QModelIndex indexForSetting(BaseSettings *setting) const
|
||||
{
|
||||
return mapFromSource(m_settings.indexForSetting(setting));
|
||||
}
|
||||
|
||||
QList<BaseSettings *> removed() const { return m_settings.removed(); }
|
||||
|
||||
private:
|
||||
LanguageClientSettingsModel &m_settings;
|
||||
};
|
||||
|
||||
class LanguageClientSettingsPageWidget : public Core::IOptionsPageWidget
|
||||
{
|
||||
public:
|
||||
@@ -153,7 +199,7 @@ private:
|
||||
void addItem(const Utils::Id &clientTypeId);
|
||||
void deleteItem();
|
||||
|
||||
LanguageClientSettingsModel &m_settings;
|
||||
FilterProxy m_settings;
|
||||
QSet<QString> &m_changedSettings;
|
||||
};
|
||||
|
||||
@@ -171,6 +217,7 @@ LanguageClientSettingsPageWidget::LanguageClientSettingsPageWidget(LanguageClien
|
||||
{
|
||||
auto mainLayout = new QVBoxLayout();
|
||||
auto layout = new QHBoxLayout();
|
||||
|
||||
m_view->setModel(&m_settings);
|
||||
m_view->setHeaderHidden(true);
|
||||
m_view->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
@@ -236,7 +283,7 @@ void LanguageClientSettingsPageWidget::resetCurrentSettings(int row)
|
||||
|
||||
m_currentSettings.setting = nullptr;
|
||||
m_currentSettings.widget = nullptr;
|
||||
m_view->setCurrentIndex(m_settings.index(row));
|
||||
m_view->setCurrentIndex(m_settings.index(row, 0));
|
||||
}
|
||||
|
||||
void LanguageClientSettingsPageWidget::applyCurrentSettings()
|
||||
@@ -264,7 +311,7 @@ void LanguageClientSettingsPageWidget::addItem(const Utils::Id &clientTypeId)
|
||||
{
|
||||
auto newSettings = generateSettings(clientTypeId);
|
||||
QTC_ASSERT(newSettings, return);
|
||||
m_view->setCurrentIndex(m_settings.index(m_settings.insertSettings(newSettings)));
|
||||
m_view->setCurrentIndex(m_settings.insertSettings(newSettings));
|
||||
}
|
||||
|
||||
void LanguageClientSettingsPageWidget::deleteItem()
|
||||
@@ -273,7 +320,7 @@ void LanguageClientSettingsPageWidget::deleteItem()
|
||||
if (!index.isValid())
|
||||
return;
|
||||
|
||||
m_settings.removeRows(index.row());
|
||||
m_settings.removeRow(index.row());
|
||||
}
|
||||
|
||||
class LanguageClientSettingsPage : public Core::IOptionsPage
|
||||
@@ -455,13 +502,13 @@ void LanguageClientSettingsModel::reset(const QList<BaseSettings *> &settings)
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int LanguageClientSettingsModel::insertSettings(BaseSettings *settings)
|
||||
QModelIndex LanguageClientSettingsModel::insertSettings(BaseSettings *settings)
|
||||
{
|
||||
int row = rowCount();
|
||||
beginInsertRows(QModelIndex(), row, row);
|
||||
m_settings.insert(row, settings);
|
||||
endInsertRows();
|
||||
return row;
|
||||
return createIndex(row, 0, settings);
|
||||
}
|
||||
|
||||
void LanguageClientSettingsModel::enableSetting(const QString &id, bool enable)
|
||||
|
@@ -71,6 +71,7 @@ public:
|
||||
LanguageFilter m_languageFilter;
|
||||
QString m_initializationOptions;
|
||||
QString m_configuration;
|
||||
bool m_showInSettings = true;
|
||||
|
||||
QJsonObject initializationOptions() const;
|
||||
QJsonValue configuration() const;
|
||||
|
@@ -215,6 +215,7 @@ public:
|
||||
CommandLine m_cmdLine;
|
||||
QString m_serverName;
|
||||
LanguageFilter m_languageFilter;
|
||||
bool m_showInSettings;
|
||||
BaseSettings::StartBehavior m_startBehavior = BaseSettings::RequiresFile;
|
||||
|
||||
std::optional<sol::protected_function> m_onInstanceStart;
|
||||
@@ -294,6 +295,8 @@ public:
|
||||
m_languageFilter.mimeTypes.push_back(v.as<QString>());
|
||||
}
|
||||
|
||||
m_showInSettings = options.get<std::optional<bool>>("showInSettings").value_or(true);
|
||||
|
||||
// get<sol::optional<>> because on MSVC, get_or(..., nullptr) fails to compile
|
||||
m_aspects = options.get<sol::optional<AspectContainer *>>("settings").value_or(nullptr);
|
||||
|
||||
@@ -569,6 +572,7 @@ LuaClientSettings::LuaClientSettings(const std::weak_ptr<LuaClientWrapper> &wrap
|
||||
m_languageFilter = w->m_languageFilter;
|
||||
m_initializationOptions = w->m_initializationOptions;
|
||||
m_startBehavior = w->m_startBehavior;
|
||||
m_showInSettings = w->m_showInSettings;
|
||||
QObject::connect(w.get(), &LuaClientWrapper::optionsChanged, &guard, [this] {
|
||||
if (auto w = m_wrapper.lock())
|
||||
m_initializationOptions = w->m_initializationOptions;
|
||||
|
@@ -11,8 +11,9 @@ local lsp = {}
|
||||
---@field languageFilter LanguageFilter The language filter deciding which files to open with the language server.
|
||||
---@field startBehavior? "AlwaysOn"|"RequiresFile"|"RequiresProject"
|
||||
---@field initializationOptions? function|table|string The initialization options to pass to the language server, either a JSON string, a table, or a function that returns either.
|
||||
---@field settings? AspectContainer
|
||||
---@field settings? AspectContainer The settings object to associate with the language server.
|
||||
---@field onStartFailed? function This callback is called when client failed to start.
|
||||
---@field showInSettings? boolean Whether the client should show up in the general Language Server list.
|
||||
local ClientOptions = {}
|
||||
|
||||
---@class LanguageFilter
|
||||
|
Reference in New Issue
Block a user