[clangd] Auto-index watches global CDB for changes.
authorSam McCall <sam.mccall@gmail.com>
Mon, 26 Nov 2018 09:51:50 +0000 (09:51 +0000)
committerSam McCall <sam.mccall@gmail.com>
Mon, 26 Nov 2018 09:51:50 +0000 (09:51 +0000)
commit6e2d2a33b6be376e52688705db22534b336f5529
tree1e7ed4997044b9a0784a97d8da0d945a05574616
parentdbfa9c3e0a34807489d31fca7dac3de5c1e0446d
[clangd] Auto-index watches global CDB for changes.

Summary:
Instead of receiving compilation commands, auto-index is triggered by just
filenames to reindex, and gets commands from the global comp DB internally.
This has advantages:
 - more of the work can be done asynchronously (fetching compilation commands
   upfront can be slow for large CDBs)
 - we get access to the CDB which can be used to retrieve interpolated commands
   for headers (useful in some cases where the original TU goes away)
 - fits nicely with the filename-only change observation from r347297

The interface to GlobalCompilationDatabase gets extended: when retrieving a
compile command, the GCDB can optionally report the project the file belongs to.
This naturally fits together with getCompileCommand: it's hard to implement one
without the other. But because most callers don't care, I've ended up with an
awkward optional-out-param-in-virtual method pattern - maybe there's a better
one.

This is the main missing integration point between ClangdServer and
BackgroundIndex, after this we should be able to add an auto-index flag.

Reviewers: ioeric, kadircet

Subscribers: MaskRay, jkorous, arphaman, cfe-commits, ilya-biryukov

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

llvm-svn: 347538
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/clangd/GlobalCompilationDatabase.h
clang-tools-extra/clangd/index/Background.cpp
clang-tools-extra/clangd/index/Background.h
clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
clang-tools-extra/unittests/clangd/BackgroundIndexTests.cpp
clang-tools-extra/unittests/clangd/GlobalCompilationDatabaseTests.cpp
clang-tools-extra/unittests/clangd/TestFS.cpp
clang-tools-extra/unittests/clangd/TestFS.h