Commit d2658e90 authored by Eric Armbruster's avatar Eric Armbruster 🍁 Committed by Christoph Cullmann
Browse files

lspclient: add rootfile pattern to detect rootpath

This makes it possible to use file patterns to detect the rootpath.

(cherry picked from commit 2239a2aa)
parent 41d8c11b
Pipeline #262911 passed with stage
in 13 minutes and 19 seconds
......@@ -40,8 +40,8 @@
typedef QMap<QString, QString> QStringMap;
// helper to find a proper root dir for the given document & file name that indicate the root dir
static QString rootForDocumentAndRootIndicationFileName(KTextEditor::Document *document, const QString &rootIndicationFileName)
// helper to find a proper root dir for the given document & file name/pattern that indicates the root dir
static QString findRootForDocument(KTextEditor::Document *document, const QStringList &rootIndicationFileNames, const QStringList &rootIndicationFilePatterns)
// search only feasible if document is local file
if (!document->url().isLocalFile()) {
......@@ -56,7 +56,15 @@ static QString rootForDocumentAndRootIndicationFileName(KTextEditor::Document *d
// the file that indicates the root dir is there => all fine
if (dir.exists(rootIndicationFileName)) {
for (const auto &fileName : rootIndicationFileNames) {
if (dir.exists(fileName)) {
return dir.absolutePath();
// look for matching file patterns
if (!dir.entryList().isEmpty()) {
return dir.absolutePath();
......@@ -70,6 +78,22 @@ static QString rootForDocumentAndRootIndicationFileName(KTextEditor::Document *d
return QString();
static QStringList indicationDataToStringList(const QJsonValue &indicationData)
if (indicationData.isArray()) {
QStringList indications;
for (auto indication : indicationData.toArray()) {
if (indication.isString()) {
indications << indication.toString();
return indications;
return {};
#include <memory>
// helper guard to handle revision (un)lock
......@@ -624,20 +648,12 @@ private:
* clangd does
if (!rootpath) {
const auto fileNamesForDetection = serverConfig.value(QStringLiteral("rootIndicationFileNames"));
if (fileNamesForDetection.isArray()) {
// we try each file name alternative in the listed order
// this allows to have preferences
const auto fileNames = fileNamesForDetection.toArray();
for (auto name : fileNames) {
if (name.isString()) {
auto root = rootForDocumentAndRootIndicationFileName(document, name.toString());
if (!root.isEmpty()) {
rootpath = root;
const auto fileNamesForDetection = indicationDataToStringList(serverConfig.value(QStringLiteral("rootIndicationFileNames")));
const auto filePatternsForDetection = indicationDataToStringList(serverConfig.value(QStringLiteral("rootIndicationFilePatterns")));
auto root = findRootForDocument(document, fileNamesForDetection, filePatternsForDetection);
if (!root.isEmpty()) {
rootpath = root;
......@@ -2686,7 +2686,8 @@ to the <quote>projectBase</quote> (as determined by the <link
linkend="kate-application-plugin-projects">Project plugin</link>) if applicable,
or otherwise relative to the document's directory. If not specified and
"rootIndicationFileNames" is an array as filenames, then a parent directory of
current document containing such a file is selected. As a last fallback, the
current document containing such a file is selected. Alternatively, if "root" is not specified and
"rootIndicationFilePatterns" is an array of file patterns, then a parent directory of the current document matching the file pattern is selected. As a last fallback, the
home directory is selected as "root". For any document, the resulting "root"
then determines whether or not a separate instance is needed. If so, the "root"
is passed as rootUri/rootPath. </para>
Supports Markdown
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