Skip to content

Commit

Permalink
improve CCDB discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
rtbo committed Nov 19, 2022
1 parent dfff0f6 commit 2daa406
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
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 2daa406

Please sign in to comment.