Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve CCDB discovery
Browse files Browse the repository at this point in the history
rtbo committed Nov 19, 2022

Verified

This commit was signed with the committer’s verified signature.
ras0q Kira Kawai
1 parent 50472d1 commit 3bfd9c0
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions source/served/extension.d
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ import std.format : format;
import std.functional : toDelegate;
import std.meta : AliasSeq;
import std.path : baseName, buildNormalizedPath, buildPath, chainPath, dirName,
globMatch, relativePath;
dirSeparator, globMatch, relativePath;
import std.string : join;

import io = std.stdio;
@@ -696,17 +696,31 @@ void delayedProjectActivation(WorkspaceD.Instance instance, string workspaceRoot

string discoverCcdb(string root)
{
import std.algorithm : count, sort;

trace("discovering CCDB in ", root);

if (fs.exists(chainPath(root, "compile_commands.json")))
return buildNormalizedPath(root, "compile_commands.json");

foreach (entry; tryDirEntries(root, "compile_commands.json", fs.SpanMode.breadth))
{
return buildNormalizedPath(entry.name);
}
string[] dbs = tryDirEntries(root, "compile_commands.json", fs.SpanMode.breadth)
.map!(e => buildNormalizedPath(e.name))
.array;

// using in priority:
// - those which have fewer directory depth
// - lexical order
dbs.sort!((a, b) {
const depthA = count(a, dirSeparator);
const depthB = count(b, dirSeparator);
if (depthA != depthB)
return depthA < depthB;
return a < b;
});

tracef("discovered following CCDB:%-(\n - %s%)", dbs);

return null;
return dbs.length ? dbs[0] : null;
}

void didLoadDubProject()

0 comments on commit 3bfd9c0

Please sign in to comment.