Git commit 45362eaa64ede7b0dbb172a5c154859c76fd6231 by Mark Nauwelaerts. Committed on 15/06/2021 at 21:53. Pushed by mnauwelaerts into branch 'master'.
lspclient: support additional search path in configuration M +20 -0 addons/lspclient/lspclientservermanager.cpp M +1 -0 addons/lspclient/settings.json M +10 -0 doc/kate/plugins.docbook https://invent.kde.org/utilities/kate/commit/45362eaa64ede7b0dbb172a5c154859c76fd6231 diff --git a/addons/lspclient/lspclientservermanager.cpp b/addons/lspclient/lspclientservermanager.cpp index 8218b054c..aad24f9d3 100644 --- a/addons/lspclient/lspclientservermanager.cpp +++ b/addons/lspclient/lspclientservermanager.cpp @@ -27,6 +27,7 @@ #include <QJsonObject> #include <QJsonParseError> #include <QRegularExpression> +#include <QStandardPaths> #include <QThread> #include <QTime> #include <QTimer> @@ -606,12 +607,31 @@ private: } if (cmdline.length() > 0) { + // optionally search in supplied path(s) + auto vpath = serverConfig.value(QStringLiteral("path")).toArray(); + if (vpath.size() > 0) { + auto cmd = QStandardPaths::findExecutable(cmdline[0]); + if (cmd.isEmpty()) { + // collect and expand in case home dir or other (environment) variable reference is used + QStringList path; + for (const auto &e : vpath) { + auto p = e.toString(); + editor->expandText(p, view, p); + path.push_back(p); + } + cmd = QStandardPaths::findExecutable(cmdline[0], path); + if (!cmd.isEmpty()) { + cmdline[0] = cmd; + } + } + } server.reset(new LSPClientServer(cmdline, root, realLangId, serverConfig.value(QStringLiteral("initializationOptions")))); connect(server.data(), &LSPClientServer::stateChanged, this, &self_type::onStateChanged, Qt::UniqueConnection); if (!server->start()) { showMessage(i18n("Failed to start server: %1", cmdline.join(QLatin1Char(' '))), KTextEditor::Message::Error); auto url = serverConfig.value(QStringLiteral("url")).toString(); if (!url.isEmpty()) { + showMessage(i18n("Please check your PATH for the binary"), KTextEditor::Message::Error); showMessage(i18n("See also %1 for installation or details", url), KTextEditor::Message::Error); } } else { diff --git a/addons/lspclient/settings.json b/addons/lspclient/settings.json index a2a3d2deb..02def28f3 100644 --- a/addons/lspclient/settings.json +++ b/addons/lspclient/settings.json @@ -84,6 +84,7 @@ }, "rust": { "command": ["rls"], + "path": ["%{ENV:HOME}/.cargo/bin", "%{ENV:USERPROFILE}/.cargo/bin"], "rootIndicationFileNames": ["Cargo.lock", "Cargo.toml"], "url": "https://github.com/rust-lang/rls", "highlightingModeRegex": "^Rust$" diff --git a/doc/kate/plugins.docbook b/doc/kate/plugins.docbook index c250791eb..c90bda3e9 100644 --- a/doc/kate/plugins.docbook +++ b/doc/kate/plugins.docbook @@ -2523,6 +2523,7 @@ To aid in the explanation below, an excerpt of that configuration is given here: }, "rust": { "command": ["rls"], + "path": ["%{ENV:HOME}/.cargo/bin", "%{ENV:USERPROFILE}/.cargo/bin"], "rootIndicationFileNames": ["Cargo.lock", "Cargo.toml"], "url": "https://github.com/rust-lang/rls", "highlightingModeRegex": "^Rust$" @@ -2540,6 +2541,15 @@ To aid in the explanation below, an excerpt of that configuration is given here: Note that each "command" may be an array or a string (in which case it is split into an array). Also, a top-level "global" entry (next to "server") is considered as well (see further below). +The specified binary is searched for in the usual way, e.g. using <literal>PATH</literal>. +If it is installed in some custom location, then the latter may have to be +extended. Or alternatively, a (sym)link or wrapper script may be used in a location +that is within the usual <literal>PATH</literal>. As illustrated above, +one may also specify a "path" that will be searched for after the standard locations. +</para> + +<para> +All of the entries in "command", "root" and "path" are subject to variable expansion. </para> <para>
