LanguageClient: move capabilities widget to inspector

The capabilities are not changeable for the user, but only there to
check whether a server is capable of a specific task. This will also
allow us to have more specialized settings widgets for specific servers
like for the java language server without the need to add the
capabilities to each of those special widgets.

Also add the dynamic capabilities to the widget so users have a complete
overview of the capabilities.

Change-Id: I9f2ed6ed11b458f0d4c67be3df632fd810023286
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2021-02-11 09:32:11 +01:00
parent c697b503e9
commit f9502a3ba6
8 changed files with 338 additions and 191 deletions

View File

@@ -740,24 +740,6 @@ public:
}
};
static QWidget *createCapabilitiesView(const QJsonValue &capabilities)
{
auto root = new Utils::JsonTreeItem("Capabilities", capabilities);
if (root->canFetchMore())
root->fetchMore();
auto capabilitiesModel = new Utils::TreeModel<Utils::JsonTreeItem>(root);
capabilitiesModel->setHeader({BaseSettingsWidget::tr("Name"),
BaseSettingsWidget::tr("Value"),
BaseSettingsWidget::tr("Type")});
auto capabilitiesView = new QTreeView();
capabilitiesView->setModel(capabilitiesModel);
capabilitiesView->setAlternatingRowColors(true);
capabilitiesView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
capabilitiesView->setItemDelegate(new JsonTreeItemDelegate);
return capabilitiesView;
}
static QString startupBehaviorString(BaseSettings::StartBehavior behavior)
{
switch (behavior) {
@@ -810,32 +792,6 @@ BaseSettingsWidget::BaseSettingsWidget(const BaseSettings *settings, QWidget *pa
connect(addMimeTypeButton, &QPushButton::pressed,
this, &BaseSettingsWidget::showAddMimeTypeDialog);
auto createInfoLabel = []() {
return new QLabel(tr("Available after server was initialized"));
};
mainLayout->addWidget(new QLabel(tr("Capabilities:")), ++row, 0, Qt::AlignTop);
QVector<Client *> clients = LanguageClientManager::clientForSetting(settings);
if (clients.isEmpty()) {
mainLayout->addWidget(createInfoLabel());
} else { // TODO move the capabilities view into a new widget outside of the settings
Client *client = clients.first();
if (client->state() == Client::Initialized)
mainLayout->addWidget(createCapabilitiesView(QJsonValue(client->capabilities())));
else
mainLayout->addWidget(createInfoLabel(), row, 1);
connect(client, &Client::finished, mainLayout, [mainLayout, row, createInfoLabel]() {
delete mainLayout->itemAtPosition(row, 1)->widget();
mainLayout->addWidget(createInfoLabel(), row, 1);
});
connect(client, &Client::initialized, mainLayout,
[mainLayout, row](
const LanguageServerProtocol::ServerCapabilities &capabilities) {
delete mainLayout->itemAtPosition(row, 1)->widget();
mainLayout->addWidget(createCapabilitiesView(QJsonValue(capabilities)), row, 1);
});
}
mainLayout->addWidget(new QLabel(tr("Initialization options:")), ++row, 0);
mainLayout->addWidget(m_initializationOptions, row, 1);
chooser->addSupportedWidget(m_initializationOptions);