diff options
| -rw-r--r-- | clang-tools-extra/clangd/index/SymbolYAML.cpp | 13 | ||||
| -rw-r--r-- | clang-tools-extra/clangd/index/SymbolYAML.h | 2 | ||||
| -rw-r--r-- | clang-tools-extra/clangd/tool/ClangdMain.cpp | 10 | 
3 files changed, 19 insertions, 6 deletions
diff --git a/clang-tools-extra/clangd/index/SymbolYAML.cpp b/clang-tools-extra/clangd/index/SymbolYAML.cpp index d90f4b0c406..78e13aefbb9 100644 --- a/clang-tools-extra/clangd/index/SymbolYAML.cpp +++ b/clang-tools-extra/clangd/index/SymbolYAML.cpp @@ -8,6 +8,7 @@  //===----------------------------------------------------------------------===//  #include "SymbolYAML.h" +#include "../Trace.h"  #include "Index.h"  #include "Serialization.h"  #include "dex/DexIndex.h" @@ -183,25 +184,31 @@ std::string SymbolToYAML(Symbol Sym) {    return OS.str();  } -std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFile, +std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFilename,                                         bool UseDex) { -  auto Buffer = llvm::MemoryBuffer::getFile(SymbolFile); +  trace::Span OverallTracer("LoadIndex"); +  auto Buffer = llvm::MemoryBuffer::getFile(SymbolFilename);    if (!Buffer) { -    llvm::errs() << "Can't open " << SymbolFile << "\n"; +    llvm::errs() << "Can't open " << SymbolFilename << "\n";      return nullptr;    }    StringRef Data = Buffer->get()->getBuffer();    llvm::Optional<SymbolSlab> Slab;    if (Data.startswith("RIFF")) { // Magic for binary index file. +    trace::Span Tracer("ParseRIFF");      if (auto RIFF = readIndexFile(Data))        Slab = std::move(RIFF->Symbols);      else        llvm::errs() << "Bad RIFF: " << llvm::toString(RIFF.takeError()) << "\n";    } else { +    trace::Span Tracer("ParseYAML");      Slab = symbolsFromYAML(Data);    } +  if (!Slab) +    return nullptr; +  trace::Span Tracer("BuildIndex");    return UseDex ? dex::DexIndex::build(std::move(*Slab))                  : MemIndex::build(std::move(*Slab), RefSlab());  } diff --git a/clang-tools-extra/clangd/index/SymbolYAML.h b/clang-tools-extra/clangd/index/SymbolYAML.h index 1af51c075ee..3f75492f2db 100644 --- a/clang-tools-extra/clangd/index/SymbolYAML.h +++ b/clang-tools-extra/clangd/index/SymbolYAML.h @@ -44,7 +44,7 @@ void SymbolsToYAML(const SymbolSlab &Symbols, llvm::raw_ostream &OS);  // Build an in-memory static index for global symbols from a symbol file.  // The size of global symbols should be relatively small, so that all symbols  // can be managed in memory. -std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFile, +std::unique_ptr<SymbolIndex> loadIndex(llvm::StringRef SymbolFilename,                                         bool UseDex = true);  } // namespace clangd diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp index ffc1fec5936..c7f4998332f 100644 --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -281,9 +281,15 @@ int main(int argc, char *argv[]) {    Opts.BuildDynamicSymbolIndex = EnableIndex;    std::unique_ptr<SymbolIndex> StaticIdx;    if (EnableIndex && !YamlSymbolFile.empty()) { -    StaticIdx = loadIndex(YamlSymbolFile, UseDex); -    Opts.StaticIndex = StaticIdx.get(); +    // Load the index asynchronously. Meanwhile SwapIndex returns no results. +    SwapIndex *Placeholder; +    StaticIdx.reset(Placeholder = new SwapIndex(llvm::make_unique<MemIndex>())); +    runAsync<void>([Placeholder] { +      if (auto Idx = loadIndex(YamlSymbolFile)) +        Placeholder->reset(std::move(Idx)); +    });    } +  Opts.StaticIndex = StaticIdx.get();    Opts.AsyncThreadsCount = WorkerThreadsCount;    clangd::CodeCompleteOptions CCOpts;  | 

