[utilities/kate] /: lspclient: optionally pass languageId when opening document
Mark Nauwelaerts
null at kde.org
Thu Dec 3 20:44:33 GMT 2020
Git commit 0f747337db17f768938cb28d449919f34ebba652 by Mark Nauwelaerts.
Committed on 03/12/2020 at 19:19.
Pushed by mnauwelaerts into branch 'master'.
lspclient: optionally pass languageId when opening document
... to allow delegating this to a language server that may be better
placed to determine so.
M +26 -3 addons/lspclient/lspclientservermanager.cpp
M +4 -1 doc/kate/plugins.docbook
https://invent.kde.org/utilities/kate/commit/0f747337db17f768938cb28d449919f34ebba652
diff --git a/addons/lspclient/lspclientservermanager.cpp b/addons/lspclient/lspclientservermanager.cpp
index 992041088..693f1f3cb 100644
--- a/addons/lspclient/lspclientservermanager.cpp
+++ b/addons/lspclient/lspclientservermanager.cpp
@@ -209,9 +209,12 @@ class LSPClientServerManagerImpl : public LSPClientServerManager
// highlightingModeRegex => language id
std::vector<std::pair<QRegularExpression, QString>> m_highlightingModeRegexToLanguageId;
-
// cache of highlighting mode => language id, to avoid massive regex matching
QHash<QString, QString> m_highlightingModeToLanguageIdCache;
+ // whether to pass the language id (key) to server when opening document
+ // most either do not care about the id, or can find out themselves
+ // (and might get confused if we pass a not so accurate one)
+ QHash<QString, bool> m_documentLanguageId;
typedef QVector<QSharedPointer<LSPClientServer>> ServerList;
@@ -310,6 +313,20 @@ public:
return QString();
}
+ QString documentLanguageId(const QString mode)
+ {
+ auto langId = languageId(mode);
+ const auto it = m_documentLanguageId.find(langId);
+ // FIXME ?? perhaps use default false
+ // most servers can find out much better on their own
+ // (though it would actually have to be confirmed as such)
+ bool useId = true;
+ if (it != m_documentLanguageId.end())
+ useId = it.value();
+
+ return useId ? langId : QString();
+ }
+
void setIncrementalSync(bool inc) override
{
m_incrementalSync = inc;
@@ -625,11 +642,17 @@ private:
const auto servers = m_serverConfig.value(QLatin1String("servers")).toObject();
for (auto it = servers.begin(); it != servers.end(); ++it) {
// get highlighting mode regex for this server, if not set, fallback to just the name
- QString highlightingModeRegex = it.value().toObject().value(QLatin1String("highlightingModeRegex")).toString();
+ const auto &server = it.value().toObject();
+ QString highlightingModeRegex = server.value(QLatin1String("highlightingModeRegex")).toString();
if (highlightingModeRegex.isEmpty()) {
highlightingModeRegex = it.key();
}
m_highlightingModeRegexToLanguageId.emplace_back(QRegularExpression(highlightingModeRegex, QRegularExpression::CaseInsensitiveOption), it.key());
+ // should we use the languageId in didOpen
+ auto docLanguageId = server.value(QLatin1String("documentLanguageId"));
+ if (docLanguageId.isBool()) {
+ m_documentLanguageId[it.key()] = docLanguageId.toBool();
+ }
}
// we could (but do not) perform restartAll here;
@@ -709,7 +732,7 @@ private:
(it->server)->didChange(it->url, it->version, (it->changes.empty()) ? doc->text() : QString(), it->changes);
}
} else {
- (it->server)->didOpen(it->url, it->version, languageId(doc->highlightingMode()), doc->text());
+ (it->server)->didOpen(it->url, it->version, documentLanguageId(doc->highlightingMode()), doc->text());
it->open = true;
}
it->modified = false;
diff --git a/doc/kate/plugins.docbook b/doc/kate/plugins.docbook
index d3a807a90..ff5cb1779 100644
--- a/doc/kate/plugins.docbook
+++ b/doc/kate/plugins.docbook
@@ -2080,7 +2080,10 @@ considered as well (see further below).
<para>
The "highlightingModeRegex" is used to map the highlighting mode as used by &kate;
to the language id of the server. If no regular expression is given, the language id
-itself is used.
+itself is used. If a "documentLanguageId" entry is set to false, then no
+language id is provided to the server when opening the document. This may
+have better results for some servers that are more precise in determining
+the document type than doing so based on a kate mode.
</para>
<para>
More information about the kde-doc-english
mailing list