diff options
| author | Sam McCall <sam.mccall@gmail.com> | 2018-11-26 16:00:11 +0000 |
|---|---|---|
| committer | Sam McCall <sam.mccall@gmail.com> | 2018-11-26 16:00:11 +0000 |
| commit | 422c828dfce022a87fe28473743c0111f582a0ee (patch) | |
| tree | 6ab8ccbd4ac9ba59cdc54148e08daaaf68fc3720 /clang-tools-extra/clangd/ClangdServer.cpp | |
| parent | d60c289625cb862eeed3f96410a7ca80d2797bcc (diff) | |
| download | bcm5719-llvm-422c828dfce022a87fe28473743c0111f582a0ee.tar.gz bcm5719-llvm-422c828dfce022a87fe28473743c0111f582a0ee.zip | |
[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
Diffstat (limited to 'clang-tools-extra/clangd/ClangdServer.cpp')
| -rw-r--r-- | clang-tools-extra/clangd/ClangdServer.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp index 8a86a5b7f8f..2b482814433 100644 --- a/clang-tools-extra/clangd/ClangdServer.cpp +++ b/clang-tools-extra/clangd/ClangdServer.cpp @@ -121,16 +121,25 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB, llvm::make_unique<UpdateIndexCallbacks>(DynamicIdx.get(), DiagConsumer), Opts.UpdateDebounce, Opts.RetentionPolicy) { - if (DynamicIdx && Opts.StaticIndex) { - MergedIdx = - llvm::make_unique<MergedIndex>(DynamicIdx.get(), Opts.StaticIndex); - Index = MergedIdx.get(); - } else if (DynamicIdx) - Index = DynamicIdx.get(); - else if (Opts.StaticIndex) - Index = Opts.StaticIndex; - else - Index = nullptr; + // Adds an index to the stack, at higher priority than existing indexes. + auto AddIndex = [&](SymbolIndex *Idx) { + if (this->Index != nullptr) { + MergedIdx.push_back(llvm::make_unique<MergedIndex>(Idx, this->Index)); + this->Index = MergedIdx.back().get(); + } else { + this->Index = Idx; + } + }; + if (Opts.StaticIndex) + AddIndex(Opts.StaticIndex); + if (Opts.BackgroundIndex) { + BackgroundIdx = llvm::make_unique<BackgroundIndex>( + Context::current().clone(), ResourceDir, FSProvider, CDB, + BackgroundIndexStorage::createDiskBackedStorageFactory()); + AddIndex(BackgroundIdx.get()); + } + if (DynamicIdx) + AddIndex(DynamicIdx.get()); } void ClangdServer::addDocument(PathRef File, StringRef Contents, @@ -501,7 +510,9 @@ ClangdServer::getUsedBytesPerFile() const { LLVM_NODISCARD bool ClangdServer::blockUntilIdleForTest(Optional<double> TimeoutSeconds) { - return WorkScheduler.blockUntilIdle(timeoutSeconds(TimeoutSeconds)); + return WorkScheduler.blockUntilIdle(timeoutSeconds(TimeoutSeconds)) && + (!BackgroundIdx || + BackgroundIdx->blockUntilIdleForTest(TimeoutSeconds)); } } // namespace clangd |

