Commit d4024eb0 authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

fallback to directory of document for root

allows to specify root paths that are relative
to current file

order of eval is:

1) absolute root paths => use 1:1
2) if relative, try if we know project base, else fall back
   to document directory if known
parent a4989299
...@@ -534,13 +534,15 @@ private: ...@@ -534,13 +534,15 @@ private:
serverConfig = json::merge(serverConfig.value(QStringLiteral("global")).toObject(), config.toObject()); serverConfig = json::merge(serverConfig.value(QStringLiteral("global")).toObject(), config.toObject());
QString rootpath; QString rootpath;
auto rootv = serverConfig.value(QStringLiteral("root")); const auto rootv = serverConfig.value(QStringLiteral("root"));
if (rootv.isString()) { if (rootv.isString()) {
auto sroot = rootv.toString(); const auto sroot = rootv.toString();
if (QDir::isAbsolutePath(sroot)) { if (QDir::isAbsolutePath(sroot)) {
rootpath = sroot; rootpath = sroot;
} else if (!projectBase.isEmpty()) { } else if (!projectBase.isEmpty()) {
rootpath = QDir(projectBase).absoluteFilePath(sroot); rootpath = QDir(projectBase).absoluteFilePath(sroot);
} else if (const auto url = document->url(); url.isValid() && url.isLocalFile()) {
rootpath = QDir(QFileInfo(url.toLocalFile()).absolutePath()).absoluteFilePath(sroot);
} }
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
"servers": { "servers": {
"bash": { "bash": {
"command": ["bash-language-server", "start"], "command": ["bash-language-server", "start"],
"root": ".",
"url": "https://github.com/bash-lsp/bash-language-server", "url": "https://github.com/bash-lsp/bash-language-server",
"highlightingModeRegex": "^Bash$" "highlightingModeRegex": "^Bash$"
}, },
......
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