[clang-tools-extra] [clangd][modules] Discover opened module files outside the compilation database (PR #218958)

Berkay Sahin via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 30 08:48:08 PDT 2026


================
@@ -942,8 +947,13 @@ void ClangdServer::outgoingCalls(
 }
 
 void ClangdServer::onFileEvent(const DidChangeWatchedFilesParams &Params) {
-  // FIXME: Do nothing for now. This will be used for indexing and potentially
-  // invalidating other caches.
+  if (!ModulesManager)
+    return;
+  bool ModulesChanged = false;
+  for (const auto &Change : Params.changes)
+    ModulesChanged |= ModulesManager->onFileEvent(Change);
+  if (ModulesChanged)
+    reparseOpenFilesIfNeeded([](PathRef) { return true; });
----------------
berkaysahiin wrote:

This routes the `workspace/didChangeWatchedFiles` events clangd already receives into the module system, so newly created/changed/deleted module files are picked up without waiting for compile_commands.json to be regenerated.

This patch only connects it to ModulesBuilder::onFileEvent.

There are two ways a module file is discovered:
- observeSourcePath, called when a file is opened in the editor, no watcher needed.
- onFileEvent, for create/change/delete on disk.

https://github.com/llvm/llvm-project/pull/218958


More information about the cfe-commits mailing list