@@ -8,10 +8,10 @@ import std.json;
8
8
import fs = std.file ;
9
9
10
10
import workspaced.api;
11
+ import workspaced.com.dcd;
11
12
12
13
import containers.hashset;
13
14
14
-
15
15
@component(" ccdb" )
16
16
class ClangCompilationDatabaseComponent : ComponentWrapper
17
17
{
@@ -24,24 +24,47 @@ class ClangCompilationDatabaseComponent : ComponentWrapper
24
24
if (! refInstance)
25
25
throw new Exception (" ccdb requires to be instanced" );
26
26
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();
32
55
}
33
56
34
- void setPath ( string filename)
57
+ string getDbPath () const
35
58
{
36
- loadDb(filename );
59
+ return config. get ! string ( " ccdb " , " dbPath " , null );
37
60
}
38
61
39
- private void loadDb (string filename )
62
+ private void loadDb (string dbPath )
40
63
{
41
64
import std.algorithm : each, filter, map;
42
65
import std.array : array;
43
66
44
- trace(" parsing CCDB from " , filename );
67
+ trace(" parsing CCDB from " , dbPath );
45
68
46
69
HashSet! string imports;
47
70
HashSet! string stringImports;
@@ -50,7 +73,7 @@ class ClangCompilationDatabaseComponent : ComponentWrapper
50
73
HashSet! string debugVersions;
51
74
52
75
{
53
- string jsonString = cast (string ) assumeUnique(fs.read(filename ));
76
+ string jsonString = cast (string ) assumeUnique(fs.read(dbPath ));
54
77
auto json = parseJSON(jsonString);
55
78
// clang db can be quite large (e.g. 100 k lines of JSON data on large projects)
56
79
// we release memory when possible to avoid having at the same time more than
@@ -62,7 +85,7 @@ class ClangCompilationDatabaseComponent : ComponentWrapper
62
85
.filter! (cc => cc.isValid)
63
86
.each! (cc =>
64
87
cc.feedOptions(imports, stringImports, fileImports, versions, debugVersions)
65
- );
88
+ );
66
89
}
67
90
68
91
_importPaths = imports[].array;
@@ -72,6 +95,15 @@ class ClangCompilationDatabaseComponent : ComponentWrapper
72
95
_debugVersions = debugVersions[].array;
73
96
}
74
97
98
+ private void unloadDb ()
99
+ {
100
+ _importPaths = null ;
101
+ _stringImportPaths = null ;
102
+ _importFiles = null ;
103
+ _versions = null ;
104
+ _debugVersions = null ;
105
+ }
106
+
75
107
// / Lists all import paths
76
108
string [] imports () @property nothrow
77
109
{
0 commit comments