Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp =================================================================== --- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp +++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp @@ -270,14 +270,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, &Opts] { + AsyncIndexLoad = runAsync([Placeholder, &Opts] { if (auto Idx = loadIndex(YamlSymbolFile, Opts.URISchemes, UseDex)) Placeholder->reset(std::move(Idx)); }); + if (RunSynchronously) + AsyncIndexLoad.wait(); } Opts.StaticIndex = StaticIdx.get(); Opts.AsyncThreadsCount = WorkerThreadsCount;