Skip to content

Commit dfff0f6

Browse files
committed
watch compile_commands.json file changes
1 parent 09c3d6b commit dfff0f6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

source/served/extension.d

+33
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,39 @@ void onDidSaveDocument(DidSaveTextDocumentParams params)
10281028
}
10291029
}
10301030

1031+
@protocolNotification("workspace/didChangeWatchedFiles")
1032+
void onDidChangeWatchedFiles(DidChangeWatchedFilesParams params)
1033+
{
1034+
foreach (c; params.changes)
1035+
{
1036+
trace("watched file did change: ", c);
1037+
1038+
string filename = c.uri.uriToFile;
1039+
1040+
auto inst = backend.getBestInstance!ClangCompilationDatabaseComponent(filename);
1041+
if (!inst)
1042+
continue;
1043+
1044+
string ccdbPath = inst.get!ClangCompilationDatabaseComponent.getDbPath();
1045+
if (!ccdbPath)
1046+
continue;
1047+
1048+
filename = filename.buildNormalizedPath();
1049+
1050+
if (filename == ccdbPath)
1051+
{
1052+
if (c.type == FileChangeType.deleted)
1053+
{
1054+
filename = discoverCcdb(inst.cwd);
1055+
tracef("CCDB file deleted. Switching from %s to %s", ccdbPath, filename ? filename : "(null)");
1056+
}
1057+
1058+
tracef("will (re)load %s", filename);
1059+
inst.get!ClangCompilationDatabaseComponent.setDbPath(filename);
1060+
}
1061+
}
1062+
}
1063+
10311064
shared static this()
10321065
{
10331066
import core.time : MonoTime;

0 commit comments

Comments
 (0)