Commit 734e6f26 authored by Mark Nauwelaerts's avatar Mark Nauwelaerts
Browse files

lspclient: add configuration option for completion presentation

parent c0ccdbeb
......@@ -154,6 +154,8 @@ class LSPClientCompletionImpl : public LSPClientCompletion
QSharedPointer<LSPClientServerManager> m_manager;
QSharedPointer<LSPClientServer> m_server;
bool m_selectedDocumentation = false;
QVector<QChar> m_triggersCompletion;
QVector<QChar> m_triggersSignature;
bool m_triggerSignature = false;
......@@ -180,6 +182,9 @@ public:
}
}
virtual void setSelectedDocumentation(bool s) override
{ m_selectedDocumentation = s; }
QVariant data(const QModelIndex &index, int role) const override
{
if (!index.isValid() || index.row() >= m_matches.size()) {
......@@ -213,8 +218,8 @@ public:
// FIXME better presentation of markdown
return match.documentation.value;
} else if (role == KTextEditor::CodeCompletionModel::ItemSelected &&
!match.argumentHintDepth && !match.documentation.value.isEmpty()) {
// TODO ?? make configurable
!match.argumentHintDepth && !match.documentation.value.isEmpty() &&
m_selectedDocumentation) {
return match.documentation.value;
}
......
......@@ -42,6 +42,7 @@ public:
{}
virtual void setServer(QSharedPointer<LSPClientServer> server) = 0;
virtual void setSelectedDocumentation(bool) = 0;
};
#endif
......@@ -45,11 +45,17 @@ LSPClientConfigPage::LSPClientConfigPage(QWidget *parent, LSPClientPlugin *plugi
top->addWidget(m_symbolExpand);
top->addWidget(m_symbolSort);
layout->addWidget(outlineBox);
outlineBox = new QGroupBox(i18n("General Options"), this);
top = new QVBoxLayout(outlineBox);
m_complDoc = new QCheckBox(i18n("Show selected completion documentation"));
top->addWidget(m_complDoc);
layout->addWidget(outlineBox);
layout->addStretch(1);
reset();
for (const auto & cb : {m_symbolDetails, m_symbolExpand, m_symbolSort, m_symbolTree})
for (const auto & cb : {m_symbolDetails, m_symbolExpand, m_symbolSort, m_symbolTree, m_complDoc})
connect(cb, &QCheckBox::toggled, this, &LSPClientConfigPage::changed);
}
......@@ -75,6 +81,8 @@ void LSPClientConfigPage::apply()
m_plugin->m_symbolExpand = m_symbolExpand->isChecked();
m_plugin->m_symbolSort = m_symbolSort->isChecked();
m_plugin->m_complDoc = m_complDoc->isChecked();
m_plugin->writeConfig();
}
......@@ -84,6 +92,8 @@ void LSPClientConfigPage::reset()
m_symbolTree->setChecked(m_plugin->m_symbolTree);
m_symbolExpand->setChecked(m_plugin->m_symbolExpand);
m_symbolSort->setChecked(m_plugin->m_symbolSort);
m_complDoc->setChecked(m_plugin->m_complDoc);
}
void LSPClientConfigPage::defaults()
......
......@@ -52,6 +52,7 @@ class LSPClientConfigPage : public KTextEditor::ConfigPage
QCheckBox* m_symbolExpand;
QCheckBox* m_symbolTree;
QCheckBox* m_symbolSort;
QCheckBox* m_complDoc;
LSPClientPlugin *m_plugin;
};
......
......@@ -67,6 +67,7 @@ void LSPClientPlugin::readConfig()
m_symbolTree = config.readEntry(QStringLiteral("SymbolTree"), true);
m_symbolExpand = config.readEntry(QStringLiteral("SymbolExpand"), true);
m_symbolSort = config.readEntry(QStringLiteral("SymbolSort"), false);
m_complDoc = config.readEntry(QStringLiteral("CompletionDocumentation"), true);
// TODO properly read/write from/to config
m_serverCmds = QMap<QString, QString> {
......@@ -86,6 +87,7 @@ void LSPClientPlugin::writeConfig() const
config.writeEntry(QStringLiteral("SymbolTree"), m_symbolTree);
config.writeEntry(QStringLiteral("SymbolExpand"), m_symbolExpand);
config.writeEntry(QStringLiteral("SymbolSort"), m_symbolSort);
config.writeEntry(QStringLiteral("CompletionDocumentation"), m_complDoc);
emit update();
}
......
......@@ -50,6 +50,7 @@ class LSPClientPlugin : public KTextEditor::Plugin
bool m_symbolExpand;
bool m_symbolTree;
bool m_symbolSort;
bool m_complDoc;
QMap<QString, QString> m_serverCmds;
Q_SIGNALS:
......
......@@ -62,6 +62,7 @@ class LSPClientPluginViewImpl : public QObject, public KXMLGUIClient
QPointer<QAction> m_findDecl;
QPointer<QAction> m_findRef;
QPointer<QAction> m_hover;
QPointer<QAction> m_complDocOn;
// views on which completions have been registered
QSet<KTextEditor::View *> m_completionViews;
......@@ -94,6 +95,11 @@ public:
m_hover = actionCollection()->addAction(QStringLiteral("lspclient_hover"), this, &self_type::hover);
m_hover->setText(i18n("Hover"));
// completion configuration
m_complDocOn = actionCollection()->addAction(QStringLiteral("lspclient_completion_doc"), this, &self_type::displayOptionChanged);
m_complDocOn->setText(i18n("Show selected completion documentation"));
m_complDocOn->setCheckable(true);
// popup menu
auto menu = new KActionMenu(i18n("LSP Client"), this);
actionCollection()->addAction(QStringLiteral("popup_lspclient"), menu);
......@@ -101,7 +107,13 @@ public:
menu->addAction(m_findDecl);
menu->addAction(m_findRef);
menu->addAction(m_hover);
menu->addSeparator();
menu->addAction(m_complDocOn);
// sync with plugin settings if updated
connect(m_plugin, &LSPClientPlugin::update, this, &self_type::configUpdated);
configUpdated();
updateState();
m_mainWindow->guiFactory()->addClient(this);
......@@ -112,6 +124,19 @@ public:
m_mainWindow->guiFactory()->removeClient(this);
}
void displayOptionChanged()
{
if (m_complDocOn)
m_completion->setSelectedDocumentation(m_complDocOn->isChecked());
}
void configUpdated()
{
if (m_complDocOn)
m_complDocOn->setChecked(m_plugin->m_complDoc);
displayOptionChanged();
}
template<typename Handler>
using LocationRequest = std::function<LSPClientServer::RequestHandle(LSPClientServer &,
const QUrl & document, const LSPPosition & pos,
......@@ -224,10 +249,13 @@ public:
m_findRef->setEnabled(refEnabled);
if (m_hover)
m_hover->setEnabled(hoverEnabled);
if (m_complDocOn)
m_complDocOn->setEnabled(server);
// update completion with relevant server
m_completion->setServer(server);
displayOptionChanged();
updateCompletion(activeView, server.get());
}
......
......@@ -8,6 +8,8 @@
<Action name="lspclient_find_declaration"/>
<Action name="lspclient_find_references"/>
<Action name="lspclient_hover"/>
<Separator/>
<Action name="lspclient_completion_doc"/>
</Menu>
</MenuBar>
<Menu name="ktexteditor_popup" noMerge="1">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment