Skip to content

Commit 4efe1cc

Browse files
committed
ccdb depends on DCD and handles dbPath config
1 parent 975f46a commit 4efe1cc

File tree

2 files changed

+47
-22
lines changed

2 files changed

+47
-22
lines changed

source/served/extension.d

+3-10
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,8 @@ void changedConfig(ConfigWorkspace target, string[] paths, served.types.Configur
111111
case "d.ccdbPath":
112112
if (config.d.ccdbPath && backend.has!ClangCompilationDatabaseComponent(workspaceFs))
113113
{
114-
backend.get!ClangCompilationDatabaseComponent(workspaceFs)
115-
.setPath(config.d.ccdbPath.userPath);
116-
117-
if (backend.has!DCDComponent(workspaceFs))
118-
backend.get!DCDComponent(workspaceFs).refreshImports();
119-
114+
const ccdbPath = config.d.ccdbPath.userPath.buildNormalizedPath();
115+
backend.get!ClangCompilationDatabaseComponent(workspaceFs).setDbPath(ccdbPath);
120116
}
121117
break;
122118
case "d.dubConfiguration":
@@ -674,10 +670,7 @@ void delayedProjectActivation(WorkspaceD.Instance instance, string workspaceRoot
674670
if (ccdbPath)
675671
{
676672
trace("starting CCDB with ", ccdbPath);
677-
instance.get!ClangCompilationDatabaseComponent.setPath(ccdbPath);
678-
679-
if (instance.has!DCDComponent)
680-
instance.get!DCDComponent.refreshImports();
673+
instance.get!ClangCompilationDatabaseComponent.setDbPath(ccdbPath);
681674
}
682675

683676
if (!loadedDub && !disableDub && !ccdbPath)

workspace-d/source/workspaced/com/ccdb.d

+44-12
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import std.json;
88
import fs = std.file;
99

1010
import workspaced.api;
11+
import workspaced.com.dcd;
1112

1213
import containers.hashset;
1314

14-
1515
@component("ccdb")
1616
class ClangCompilationDatabaseComponent : ComponentWrapper
1717
{
@@ -24,24 +24,47 @@ class ClangCompilationDatabaseComponent : ComponentWrapper
2424
if (!refInstance)
2525
throw new Exception("ccdb requires to be instanced");
2626

27-
importPathProvider = &imports;
28-
stringImportPathProvider = &stringImports;
29-
importFilesProvider = &fileImports;
30-
projectVersionsProvider = &versions;
31-
debugSpecificationsProvider = &debugVersions;
27+
if (config.get!bool("ccdb", "registerImportProvider", true))
28+
importPathProvider = &imports;
29+
if (config.get!bool("ccdb", "registerStringImportProvider", true))
30+
stringImportPathProvider = &stringImports;
31+
if (config.get!bool("ccdb", "registerImportFilesProvider", false))
32+
importFilesProvider = &fileImports;
33+
if (config.get!bool("ccdb", "registerProjectVersionsProvider", true))
34+
projectVersionsProvider = &versions;
35+
if (config.get!bool("ccdb", "registerDebugSpecificationsProvider", true))
36+
debugSpecificationsProvider = &debugVersions;
37+
38+
if (auto dbPath = config.get!string("ccdb", "dbPath", null))
39+
loadDb(dbPath);
40+
}
41+
42+
void setDbPath(string dbPath)
43+
{
44+
import std.path : buildNormalizedPath;
45+
46+
if (dbPath)
47+
loadDb(dbPath);
48+
else
49+
unloadDb();
50+
51+
config.set("ccdb", "dbPath", dbPath.buildNormalizedPath());
52+
53+
if (refInstance.has!DCDComponent)
54+
refInstance.get!DCDComponent.refreshImports();
3255
}
3356

34-
void setPath(string filename)
57+
string getDbPath() const
3558
{
36-
loadDb(filename);
59+
return config.get!string("ccdb", "dbPath", null);
3760
}
3861

39-
private void loadDb(string filename)
62+
private void loadDb(string dbPath)
4063
{
4164
import std.algorithm : each, filter, map;
4265
import std.array : array;
4366

44-
trace("parsing CCDB from ", filename);
67+
trace("parsing CCDB from ", dbPath);
4568

4669
HashSet!string imports;
4770
HashSet!string stringImports;
@@ -50,7 +73,7 @@ class ClangCompilationDatabaseComponent : ComponentWrapper
5073
HashSet!string debugVersions;
5174

5275
{
53-
string jsonString = cast(string) assumeUnique(fs.read(filename));
76+
string jsonString = cast(string) assumeUnique(fs.read(dbPath));
5477
auto json = parseJSON(jsonString);
5578
// clang db can be quite large (e.g. 100 k lines of JSON data on large projects)
5679
// we release memory when possible to avoid having at the same time more than
@@ -62,7 +85,7 @@ class ClangCompilationDatabaseComponent : ComponentWrapper
6285
.filter!(cc => cc.isValid)
6386
.each!(cc =>
6487
cc.feedOptions(imports, stringImports, fileImports, versions, debugVersions)
65-
);
88+
);
6689
}
6790

6891
_importPaths = imports[].array;
@@ -72,6 +95,15 @@ class ClangCompilationDatabaseComponent : ComponentWrapper
7295
_debugVersions = debugVersions[].array;
7396
}
7497

98+
private void unloadDb()
99+
{
100+
_importPaths = null;
101+
_stringImportPaths = null;
102+
_importFiles = null;
103+
_versions = null;
104+
_debugVersions = null;
105+
}
106+
75107
/// Lists all import paths
76108
string[] imports() @property nothrow
77109
{

0 commit comments

Comments
 (0)