Index: clangd/tool/ClangdMain.cpp =================================================================== --- clangd/tool/ClangdMain.cpp +++ clangd/tool/ClangdMain.cpp @@ -271,14 +271,17 @@ Opts.ResourceDir = ResourceDir; Opts.BuildDynamicSymbolIndex = EnableIndex; std::unique_ptr StaticIdx; + std::future AsyncIndexLoad; // Block exit while loading the index. if (EnableIndex && !YamlSymbolFile.empty()) { // Load the index asynchronously. Meanwhile SwapIndex returns no results. SwapIndex *Placeholder; StaticIdx.reset(Placeholder = new SwapIndex(llvm::make_unique())); - runAsync([Placeholder] { + AsyncIndexLoad = runAsync([Placeholder] { if (auto Idx = loadIndex(YamlSymbolFile)) Placeholder->reset(std::move(Idx)); }); + if (RunSynchronously) + AsyncIndexLoad.wait(); } Opts.StaticIndex = StaticIdx.get(); Opts.AsyncThreadsCount = WorkerThreadsCount;