[clangd] Enable auto-index behind a flag.
authorSam McCall <sam.mccall@gmail.com>
Mon, 26 Nov 2018 16:00:11 +0000 (16:00 +0000)
committerSam McCall <sam.mccall@gmail.com>
Mon, 26 Nov 2018 16:00:11 +0000 (16:00 +0000)
commit422c828dfce022a87fe28473743c0111f582a0ee
tree6ab8ccbd4ac9ba59cdc54148e08daaaf68fc3720
parentd60c289625cb862eeed3f96410a7ca80d2797bcc
[clangd] Enable auto-index behind a flag.

Summary:
Ownership and configuration:
The auto-index (background index) is maintained by ClangdServer, like Dynamic.
(This means ClangdServer will be able to enqueue preamble indexing in future).
For now it's enabled by a simple boolean flag in ClangdServer::Options, but
we probably want to eventually allow injecting the storage strategy.

New 'sync' command:
In order to meaningfully test the integration (not just unit-test components)
we need a way for tests to ensure the asynchronous index reads/writes occur
before a certain point.
Because these tests and assertions are few, I think exposing an explicit "sync"
command for use in tests is simpler than allowing threading to be completely
disabled in the background index (as we do for TUScheduler).

Bugs:
I fixed a couple of trivial bugs I found while testing, but there's one I can't.
JSONCompilationDatabase::getAllFiles() may return relative paths, and currently
we trigger an assertion that assumes they are absolute.
There's no efficient way to resolve them (you have to retrieve the corresponding
command and then resolve against its directory property). In general I think
this behavior is broken and we should fix it in JSONCompilationDatabase and
require CompilationDatabase::getAllFiles() to be absolute.

Reviewers: kadircet

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

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

llvm-svn: 347567
15 files changed:
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/ClangdServer.h
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/clangd/index/Background.cpp
clang-tools-extra/clangd/index/Background.h
clang-tools-extra/clangd/index/BackgroundIndexStorage.cpp
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/test/clangd/Inputs/background-index/compile_commands.json [new file with mode: 0644]
clang-tools-extra/test/clangd/Inputs/background-index/definition.jsonrpc [new file with mode: 0644]
clang-tools-extra/test/clangd/Inputs/background-index/foo.cpp [new file with mode: 0644]
clang-tools-extra/test/clangd/Inputs/background-index/foo.h [new file with mode: 0644]
clang-tools-extra/test/clangd/background-index.test [new file with mode: 0644]
clang-tools-extra/unittests/clangd/BackgroundIndexTests.cpp