[PATCH] D49267: [clangd] Watch for changes in compile_commands.json

Simon Marchi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 24 07:54:39 PDT 2018


simark added inline comments.


================
Comment at: clangd/ClangdLSPServer.cpp:430
     CDB.clear();
-
-    reparseOpenedFiles();
+    compileCommandsChangePost(CCChangeData);
   }
----------------
malaperle wrote:
> ilya-biryukov wrote:
> > Maybe keep the old logic of reparsing all open files? This would make the change way simpler and I don't think we need this extra complexity in the long run, when we have better integration with the build system.
> > 
> > ClangdServer will reuse the preamble if compile command didn't change anyway, so reparse will be very fast and shouldn't be affected.
> > If the compile command does change, we'll retrigger the full rebuild.
> I think the change is not that complex but brings much added value. About the integration with the build system, there are many build systems out there so I don't think better integration will be useful in many scenarios (plain make, custom builds, etc). This solution is generic enough so that any build system that generates compile_commands.json will be supported in a pretty good way.
@malaperle also suggested an alternative way of doing it.  Instead of saving the the compile commands in a custom structure before clearing the cache, we could save the compile flags in the `ParsedAST` object.  When some compile_commands.json changes, we can compare the new compile flags with this saved copy.  I think it would make the code a bit more straightforward.


================
Comment at: clangd/clients/clangd-vscode/src/extension.ts:35
         ['cpp', 'c', 'cc', 'cxx', 'c++', 'm', 'mm', 'h', 'hh', 'hpp', 'hxx', 'inc'].join() + '}';
+    const compileCommandsFilePattern: string = '**/compile_commands.json';
     const clientOptions: vscodelc.LanguageClientOptions = {
----------------
ilya-biryukov wrote:
> These watches apply to the children of the workspace root only, right?
> E.g., I quite often open the workspace in 'llvm/tools/clang/tools/extra/clangd', would my `compile_commands.json`, that's outside the workspace, be watched for changes?
You are right, I don't think files outside the workspace would get watched.

For your use case, we'll need clangd to watch (or ask the client to watch) the file.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D49267





More information about the cfe-commits mailing list