Commit 45362eaa authored by Mark Nauwelaerts's avatar Mark Nauwelaerts
Browse files

lspclient: support additional search path in configuration

parent f8a17b1f
......@@ -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 {
......
......@@ -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$"
......
......@@ -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>
......
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