Commit f82159c8 authored by Mark Nauwelaerts's avatar Mark Nauwelaerts
Browse files

lspclient: make function parentheses auto-completion optional

parent 969afc2b
......@@ -141,6 +141,7 @@ class LSPClientCompletionImpl : public LSPClientCompletion
QSharedPointer<LSPClientServer> m_server;
bool m_selectedDocumentation = false;
bool m_signatureHelp = true;
bool m_complParens = true;
QVector<QChar> m_triggersCompletion;
QVector<QChar> m_triggersSignature;
......@@ -180,6 +181,11 @@ public:
m_signatureHelp = s;
}
void setCompleteParens(bool s) override
{
m_complParens = s;
}
QVariant data(const QModelIndex &index, int role) const override
{
if (!index.isValid() || index.row() >= m_matches.size()) {
......@@ -340,7 +346,8 @@ public:
// This is a function
const auto &m = m_matches.at(index.row());
// add parentheses if function and guestimated meaningful for language in question
bool addParens = isFunctionKind(m.kind) && m_triggersSignature.contains(QLatin1Char('('));
// this covers at least the common cases such as clangd, python, etc
bool addParens = m_complParens && isFunctionKind(m.kind) && m_triggersSignature.contains(QLatin1Char('('));
if (addParens) {
matching += QStringLiteral("()");
}
......
......@@ -31,6 +31,7 @@ public:
virtual void setServer(QSharedPointer<LSPClientServer> server) = 0;
virtual void setSelectedDocumentation(bool) = 0;
virtual void setSignatureHelp(bool) = 0;
virtual void setCompleteParens(bool) = 0;
};
#endif
......@@ -52,6 +52,7 @@ LSPClientConfigPage::LSPClientConfigPage(QWidget *parent, LSPClientPlugin *plugi
ui->chkSymbolTree,
ui->chkComplDoc,
ui->chkRefDeclaration,
ui->chkComplParens,
ui->chkDiagnostics,
ui->chkDiagnosticsMark,
ui->chkDiagnosticsHover,
......@@ -123,6 +124,7 @@ void LSPClientConfigPage::apply()
m_plugin->m_complDoc = ui->chkComplDoc->isChecked();
m_plugin->m_refDeclaration = ui->chkRefDeclaration->isChecked();
m_plugin->m_complParens = ui->chkComplParens->isChecked();
m_plugin->m_diagnostics = ui->chkDiagnostics->isChecked();
m_plugin->m_diagnosticsHighlight = ui->chkDiagnosticsHighlight->isChecked();
......@@ -162,6 +164,7 @@ void LSPClientConfigPage::reset()
ui->chkComplDoc->setChecked(m_plugin->m_complDoc);
ui->chkRefDeclaration->setChecked(m_plugin->m_refDeclaration);
ui->chkComplParens->setChecked(m_plugin->m_complParens);
ui->chkDiagnostics->setChecked(m_plugin->m_diagnostics);
ui->chkDiagnosticsHighlight->setChecked(m_plugin->m_diagnosticsHighlight);
......
......@@ -25,6 +25,7 @@ static const QString CONFIG_SYMBOL_EXPAND{QStringLiteral("SymbolExpand")};
static const QString CONFIG_SYMBOL_SORT{QStringLiteral("SymbolSort")};
static const QString CONFIG_COMPLETION_DOC{QStringLiteral("CompletionDocumentation")};
static const QString CONFIG_REFERENCES_DECLARATION{QStringLiteral("ReferencesDeclaration")};
static const QString CONFIG_COMPLETION_PARENS{QStringLiteral("CompletionParens")};
static const QString CONFIG_AUTO_HOVER{QStringLiteral("AutoHover")};
static const QString CONFIG_TYPE_FORMATTING{QStringLiteral("TypeFormatting")};
static const QString CONFIG_INCREMENTAL_SYNC{QStringLiteral("IncrementalSync")};
......@@ -95,6 +96,7 @@ void LSPClientPlugin::readConfig()
m_symbolSort = config.readEntry(CONFIG_SYMBOL_SORT, false);
m_complDoc = config.readEntry(CONFIG_COMPLETION_DOC, true);
m_refDeclaration = config.readEntry(CONFIG_REFERENCES_DECLARATION, true);
m_complParens = config.readEntry(CONFIG_COMPLETION_PARENS, true);
m_autoHover = config.readEntry(CONFIG_AUTO_HOVER, true);
m_onTypeFormatting = config.readEntry(CONFIG_TYPE_FORMATTING, false);
m_incrementalSync = config.readEntry(CONFIG_INCREMENTAL_SYNC, false);
......@@ -121,6 +123,7 @@ void LSPClientPlugin::writeConfig() const
config.writeEntry(CONFIG_SYMBOL_SORT, m_symbolSort);
config.writeEntry(CONFIG_COMPLETION_DOC, m_complDoc);
config.writeEntry(CONFIG_REFERENCES_DECLARATION, m_refDeclaration);
config.writeEntry(CONFIG_COMPLETION_PARENS, m_complParens);
config.writeEntry(CONFIG_AUTO_HOVER, m_autoHover);
config.writeEntry(CONFIG_TYPE_FORMATTING, m_onTypeFormatting);
config.writeEntry(CONFIG_INCREMENTAL_SYNC, m_incrementalSync);
......
......@@ -42,6 +42,7 @@ public:
bool m_symbolSort = false;
bool m_complDoc = false;
bool m_refDeclaration = false;
bool m_complParens = false;
bool m_diagnostics = false;
bool m_diagnosticsHighlight = false;
bool m_diagnosticsMark = false;
......
......@@ -396,6 +396,7 @@ class LSPClientActionView : public QObject
QPointer<QAction> m_complDocOn;
QPointer<QAction> m_signatureHelp;
QPointer<QAction> m_refDeclaration;
QPointer<QAction> m_complParens;
QPointer<QAction> m_autoHover;
QPointer<QAction> m_onTypeFormatting;
QPointer<QAction> m_incrementalSync;
......@@ -549,6 +550,9 @@ public:
m_refDeclaration = actionCollection()->addAction(QStringLiteral("lspclient_references_declaration"), this, &self_type::displayOptionChanged);
m_refDeclaration->setText(i18n("Include declaration in references"));
m_refDeclaration->setCheckable(true);
m_complParens = actionCollection()->addAction(QStringLiteral("lspclient_completion_parens"), this, &self_type::displayOptionChanged);
m_complParens->setText(i18n("Add parentheses upon function completion"));
m_complParens->setCheckable(true);
m_autoHover = actionCollection()->addAction(QStringLiteral("lspclient_auto_hover"), this, &self_type::displayOptionChanged);
m_autoHover->setText(i18n("Show hover information"));
m_autoHover->setCheckable(true);
......@@ -618,6 +622,7 @@ public:
moreOptions->addAction(m_complDocOn);
moreOptions->addAction(m_signatureHelp);
moreOptions->addAction(m_refDeclaration);
moreOptions->addAction(m_complParens);
moreOptions->addAction(m_autoHover);
moreOptions->addAction(m_onTypeFormatting);
moreOptions->addAction(m_incrementalSync);
......@@ -879,6 +884,9 @@ public:
if (m_refDeclaration) {
m_refDeclaration->setChecked(m_plugin->m_refDeclaration);
}
if (m_complParens) {
m_complParens->setChecked(m_plugin->m_complParens);
}
if (m_autoHover) {
m_autoHover->setChecked(m_plugin->m_autoHover);
}
......@@ -2345,6 +2353,9 @@ public:
if (m_signatureHelp) {
m_completion->setSignatureHelp(m_signatureHelp->isChecked());
}
if (m_complParens) {
m_completion->setCompleteParens(m_complParens->isChecked());
}
updateCompletion(activeView, server.data());
// update hover with relevant server
......
......@@ -62,6 +62,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkComplParens">
<property name="text">
<string>Add parentheses upon function completion</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkAutoHover">
<property name="text">
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
<gui name="lspclient" library="lspclient" version="15" translationDomain="lspclient">
<gui name="lspclient" library="lspclient" version="16" translationDomain="lspclient">
<MenuBar>
<Menu name="LSPClient Menubar">
<text>LSP Client</text>
......@@ -28,6 +28,7 @@
<Action name="lspclient_completion_doc"/>
<Action name="lspclient_signature_help"/>
<Action name="lspclient_references_declaration"/>
<Action name="lspclient_completion_parens"/>
<Action name="lspclient_auto_hover"/>
<Action name="lspclient_type_formatting"/>
<Action name="lspclient_incremental_sync"/>
......
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