diff --git a/clang-tools-extra/clangd/indexer/IndexerMain.cpp b/clang-tools-extra/clangd/indexer/IndexerMain.cpp --- a/clang-tools-extra/clangd/indexer/IndexerMain.cpp +++ b/clang-tools-extra/clangd/indexer/IndexerMain.cpp @@ -43,6 +43,16 @@ std::unique_ptr create() override { SymbolCollector::Options Opts; Opts.CountReferences = true; + Opts.FileFilter = [&](const SourceManager &SM, FileID FID) { + const auto *F = SM.getFileEntryForID(FID); + if (!F) + return false; // Skip invalid files. + auto AbsPath = getCanonicalPath(F, SM); + if (!AbsPath) + return false; // Skip files without absolute path. + std::lock_guard Lock(FilesMu); + return Files.insert(*AbsPath).second; // Skip already processed files. + }; return createStaticIndexingAction( Opts, [&](SymbolSlab S) { @@ -56,7 +66,7 @@ } }, [&](RefSlab S) { - std::lock_guard Lock(SymbolsMu); + std::lock_guard Lock(RefsMu); for (const auto &Sym : S) { // Deduplication happens during insertion. for (const auto &Ref : Sym.second) @@ -64,7 +74,7 @@ } }, [&](RelationSlab S) { - std::lock_guard Lock(SymbolsMu); + std::lock_guard Lock(RelsMu); for (const auto &R : S) { Relations.insert(R); } @@ -82,9 +92,13 @@ private: IndexFileIn &Result; + std::mutex FilesMu; + llvm::StringSet<> Files; std::mutex SymbolsMu; SymbolSlab::Builder Symbols; + std::mutex RefsMu; RefSlab::Builder Refs; + std::mutex RelsMu; RelationSlab::Builder Relations; };