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,19 @@ 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); + if (Files.count(*AbsPath) != 0) + return false; // Skip already processed files. + Files.insert(*AbsPath); + return true; + }; return createStaticIndexingAction( Opts, [&](SymbolSlab S) { @@ -56,7 +69,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 +77,7 @@ } }, [&](RelationSlab S) { - std::lock_guard Lock(SymbolsMu); + std::lock_guard Lock(RelsMu); for (const auto &R : S) { Relations.insert(R); } @@ -82,9 +95,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; };