[utilities/kate] /: lspclient: optionally adjust the trigger character sets suggested by servers
Christoph Cullmann
null at kde.org
Sun Dec 11 13:55:33 GMT 2022
Git commit f7eee57fe832dd8df262356373468f24e807e9ac by Christoph Cullmann, on behalf of Mark Nauwelaerts.
Committed on 11/12/2022 at 13:43.
Pushed by cullmann into branch 'master'.
lspclient: optionally adjust the trigger character sets suggested by servers
M +12 -0 addons/lspclient/lspclientserver.cpp
M +8 -0 addons/lspclient/lspclientserver.h
M +23 -1 addons/lspclient/lspclientservermanager.cpp
M +4 -0 doc/kate/plugins.docbook
https://invent.kde.org/utilities/kate/commit/f7eee57fe832dd8df262356373468f24e807e9ac
diff --git a/addons/lspclient/lspclientserver.cpp b/addons/lspclient/lspclientserver.cpp
index f8db5502a..227bcbf69 100644
--- a/addons/lspclient/lspclientserver.cpp
+++ b/addons/lspclient/lspclientserver.cpp
@@ -1356,10 +1356,22 @@ private:
}
}
+ void applyTriggerOverride(QVector<QChar> &characters, const TriggerCharactersOverride &adjust)
+ {
+ // these are expected 'small' sets, so the simple way should do
+ for (const auto &c : adjust.exclude) {
+ characters.removeAll(c);
+ }
+ characters.append(adjust.include);
+ }
+
void onInitializeReply(const QJsonValue &value)
{
// only parse parts that we use later on
from_json(m_capabilities, value.toObject().value(QStringLiteral("capabilities")).toObject());
+ // tweak triggers as specified
+ applyTriggerOverride(m_capabilities.completionProvider.triggerCharacters, m_config.completion);
+ applyTriggerOverride(m_capabilities.signatureHelpProvider.triggerCharacters, m_config.signature);
// finish init
initialized();
}
diff --git a/addons/lspclient/lspclientserver.h b/addons/lspclient/lspclientserver.h
index fe63c24a4..51def7fdc 100644
--- a/addons/lspclient/lspclientserver.h
+++ b/addons/lspclient/lspclientserver.h
@@ -106,11 +106,19 @@ public:
using FoldersType = std::optional<QList<LSPWorkspaceFolder>>;
+ // optionally adjust server provided/suggest trigger characters
+ struct TriggerCharactersOverride {
+ QVector<QChar> exclude;
+ QVector<QChar> include;
+ };
+
// collect additional tweaks into a helper struct to avoid ever growing parameter list
// (which then also needs to be duplicated in a few places)
struct ExtraServerConfig {
FoldersType folders;
LSPClientCapabilities caps;
+ TriggerCharactersOverride completion;
+ TriggerCharactersOverride signature;
};
LSPClientServer(const QStringList &server,
diff --git a/addons/lspclient/lspclientservermanager.cpp b/addons/lspclient/lspclientservermanager.cpp
index 6ed18408a..6f12f667d 100644
--- a/addons/lspclient/lspclientservermanager.cpp
+++ b/addons/lspclient/lspclientservermanager.cpp
@@ -101,6 +101,21 @@ static QStringList indicationDataToStringList(const QJsonValue &indicationData)
return {};
}
+static LSPClientServer::TriggerCharactersOverride parseTriggerOverride(const QJsonValue &json)
+{
+ LSPClientServer::TriggerCharactersOverride adjust;
+ if (json.isObject()) {
+ auto ob = json.toObject();
+ for (const auto &c : ob.value(QStringLiteral("exclude")).toString()) {
+ adjust.exclude.push_back(c);
+ }
+ for (const auto &c : ob.value(QStringLiteral("include")).toString()) {
+ adjust.include.push_back(c);
+ }
+ }
+ return adjust;
+}
+
#include <memory>
// helper guard to handle revision (un)lock
@@ -807,8 +822,15 @@ private:
}
// spin up using currently configured client capabilities
auto &caps = m_clientCapabilities;
+ // extract some more additional config
+ auto completionOverride = parseTriggerOverride(serverConfig.value(QStringLiteral("completionTriggerCharacters")));
+ auto signatureOverride = parseTriggerOverride(serverConfig.value(QStringLiteral("signatureTriggerCharacters")));
// request server and setup
- server.reset(new LSPClientServer(cmdline, root, realLangId, serverConfig.value(QStringLiteral("initializationOptions")), {folders, caps}));
+ server.reset(new LSPClientServer(cmdline,
+ root,
+ realLangId,
+ serverConfig.value(QStringLiteral("initializationOptions")),
+ {folders, caps, completionOverride, signatureOverride}));
connect(server.data(), &LSPClientServer::stateChanged, this, &self_type::onStateChanged, Qt::UniqueConnection);
if (!server->start(m_plugin->m_debugMode)) {
QString message = i18n("Failed to start server: %1", cmdline.join(QLatin1Char(' ')));
diff --git a/doc/kate/plugins.docbook b/doc/kate/plugins.docbook
index 520ff3cfb..177d5237f 100644
--- a/doc/kate/plugins.docbook
+++ b/doc/kate/plugins.docbook
@@ -2671,6 +2671,10 @@ entry object may also have an "initializationOptions" entry, which is passed
along to the server as part of the 'initialize' method.
If present, a "settings" entry is passed to the server by means of the
'workspace/didChangeConfiguration' notification.
+Either of "completionTriggerCharacters" or "signatureTriggerCharacters" may be
+specified as a JSON object with string members "exclude" and/or "include".
+These will be used to respectively exclude or add some characters to
+the respective trigger set as provided by the server.
</para>
<para>
More information about the kde-doc-english
mailing list