Skip to content

Commit

Permalink
watch compile_commands.json file changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rtbo committed Nov 19, 2022
1 parent 4efe1cc commit 50472d1
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions source/served/extension.d
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,39 @@ void onDidSaveDocument(DidSaveTextDocumentParams params)
}
}

@protocolNotification("workspace/didChangeWatchedFiles")
void onDidChangeWatchedFiles(DidChangeWatchedFilesParams params)
{
foreach (c; params.changes)
{
trace("watched file did change: ", c);

string filename = c.uri.uriToFile;

auto inst = backend.getBestInstance!ClangCompilationDatabaseComponent(filename);
if (!inst)
continue;

string ccdbPath = inst.get!ClangCompilationDatabaseComponent.getDbPath();
if (!ccdbPath)
continue;

filename = filename.buildNormalizedPath();

if (filename == ccdbPath)
{
if (c.type == FileChangeType.deleted)
{
filename = discoverCcdb(inst.cwd);
tracef("CCDB file deleted. Switching from %s to %s", ccdbPath, filename ? filename : "(null)");
}

tracef("will (re)load %s", filename);
inst.get!ClangCompilationDatabaseComponent.setDbPath(filename);
}
}
}

shared static this()
{
import core.time : MonoTime;
Expand Down

0 comments on commit 50472d1

Please sign in to comment.