From 50472d188f0aa75d452330c09986db151d42d52d Mon Sep 17 00:00:00 2001 From: Remi Thebault Date: Sat, 19 Nov 2022 14:59:53 +0100 Subject: [PATCH] watch compile_commands.json file changes --- source/served/extension.d | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/source/served/extension.d b/source/served/extension.d index a32f325e..c85fcd42 100644 --- a/source/served/extension.d +++ b/source/served/extension.d @@ -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;