[clangd] Handle workspace/didChangeWatchedFiles

Summary:
The client can send notifications when it detects watched files have
changed. This patch adds the protocol handling for this type of notification.
For now, the notification will be passed down to the ClangdServer, but it will
not be acted upon. However, this will become useful for the indexer to react
to file changes.
The events could also potentially be used to invalidate other caches
(compilation database, etc).

This change also updates the VSCode extension so that it sends the events.

Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>

Reviewers: ilya-biryukov, Nebiroth

Subscribers: ilya-biryukov

Tags: #clang-tools-extra

Differential Revision: https://reviews.llvm.org/D38422

llvm-svn: 314693
diff --git a/clang-tools-extra/clangd/ProtocolHandlers.cpp b/clang-tools-extra/clangd/ProtocolHandlers.cpp
index 544c44c..936c673 100644
--- a/clang-tools-extra/clangd/ProtocolHandlers.cpp
+++ b/clang-tools-extra/clangd/ProtocolHandlers.cpp
@@ -226,6 +226,25 @@
   ProtocolCallbacks &Callbacks;
 };
 
+struct WorkspaceDidChangeWatchedFilesHandler : Handler {
+  WorkspaceDidChangeWatchedFilesHandler(JSONOutput &Output,
+                                        ProtocolCallbacks &Callbacks)
+      : Handler(Output), Callbacks(Callbacks) {}
+
+  void handleNotification(llvm::yaml::MappingNode *Params) {
+    auto DCWFP = DidChangeWatchedFilesParams::parse(Params, Output);
+    if (!DCWFP) {
+      Output.log("Failed to decode DidChangeWatchedFilesParams.\n");
+      return;
+    }
+
+    Callbacks.onFileEvent(*DCWFP);
+  }
+
+private:
+  ProtocolCallbacks &Callbacks;
+};
+
 } // namespace
 
 void clangd::registerCallbackHandlers(JSONRPCDispatcher &Dispatcher,
@@ -264,5 +283,8 @@
       llvm::make_unique<GotoDefinitionHandler>(Out, Callbacks));
   Dispatcher.registerHandler(
       "textDocument/switchSourceHeader",
-      llvm::make_unique<SwitchSourceHeaderHandler>(Out, Callbacks));    
+      llvm::make_unique<SwitchSourceHeaderHandler>(Out, Callbacks));
+  Dispatcher.registerHandler(
+      "workspace/didChangeWatchedFiles",
+      llvm::make_unique<WorkspaceDidChangeWatchedFilesHandler>(Out, Callbacks));
 }