Commit 0d0e526f authored by Mark Nauwelaerts's avatar Mark Nauwelaerts
Browse files

lspclient: specify null rootUri if no project and empty root config

parent 70763b8a
...@@ -536,7 +536,7 @@ private: ...@@ -536,7 +536,7 @@ private:
// NOTE that also covers a form of environment substitution using %{ENV:XYZ} // NOTE that also covers a form of environment substitution using %{ENV:XYZ}
auto editor = KTextEditor::Editor::instance(); auto editor = KTextEditor::Editor::instance();
QString rootpath; std::optional<QString> rootpath;
const auto rootv = serverConfig.value(QStringLiteral("root")); const auto rootv = serverConfig.value(QStringLiteral("root"));
if (rootv.isString()) { if (rootv.isString()) {
auto sroot = rootv.toString(); auto sroot = rootv.toString();
...@@ -545,7 +545,11 @@ private: ...@@ -545,7 +545,11 @@ private:
rootpath = sroot; rootpath = sroot;
} else if (!projectBase.isEmpty()) { } else if (!projectBase.isEmpty()) {
rootpath = QDir(projectBase).absoluteFilePath(sroot); rootpath = QDir(projectBase).absoluteFilePath(sroot);
} else if (sroot.isEmpty()) {
// empty root; so we are convinced the server can handle null rootUri
rootpath = QString();
} else if (const auto url = document->url(); url.isValid() && url.isLocalFile()) { } else if (const auto url = document->url(); url.isValid() && url.isLocalFile()) {
// likewise, but use safer traditional approach and specify rootUri
rootpath = QDir(QFileInfo(url.toLocalFile()).absolutePath()).absoluteFilePath(sroot); rootpath = QDir(QFileInfo(url.toLocalFile()).absolutePath()).absoluteFilePath(sroot);
} }
} }
...@@ -555,15 +559,16 @@ private: ...@@ -555,15 +559,16 @@ private:
* this is required for some LSP servers like rls that don't handle that on their own like * this is required for some LSP servers like rls that don't handle that on their own like
* clangd does * clangd does
*/ */
if (rootpath.isEmpty()) { if (!rootpath) {
const auto fileNamesForDetection = serverConfig.value(QStringLiteral("rootIndicationFileNames")); const auto fileNamesForDetection = serverConfig.value(QStringLiteral("rootIndicationFileNames"));
if (fileNamesForDetection.isArray()) { if (fileNamesForDetection.isArray()) {
// we try each file name alternative in the listed order // we try each file name alternative in the listed order
// this allows to have preferences // this allows to have preferences
for (auto name : fileNamesForDetection.toArray()) { for (auto name : fileNamesForDetection.toArray()) {
if (name.isString()) { if (name.isString()) {
rootpath = rootForDocumentAndRootIndicationFileName(document, name.toString()); auto root = rootForDocumentAndRootIndicationFileName(document, name.toString());
if (!rootpath.isEmpty()) { if (!root.isEmpty()) {
rootpath = root;
break; break;
} }
} }
...@@ -572,11 +577,11 @@ private: ...@@ -572,11 +577,11 @@ private:
} }
// last fallback: home directory // last fallback: home directory
if (rootpath.isEmpty()) { if (!rootpath) {
rootpath = QDir::homePath(); rootpath = QDir::homePath();
} }
auto root = QUrl::fromLocalFile(rootpath); auto root = rootpath && !rootpath->isEmpty() ? QUrl::fromLocalFile(*rootpath) : QUrl();
auto &serverinfo = m_servers[root][langId]; auto &serverinfo = m_servers[root][langId];
auto &server = serverinfo.server; auto &server = serverinfo.server;
if (!server) { if (!server) {
......
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