Index: clang-tools-extra/trunk/clangd/index/SymbolCollector.h =================================================================== --- clang-tools-extra/trunk/clangd/index/SymbolCollector.h +++ clang-tools-extra/trunk/clangd/index/SymbolCollector.h @@ -60,6 +60,9 @@ bool CountReferences = false; /// The symbol ref kinds that will be collected. /// If not set, SymbolCollector will not collect refs. + /// Note that references of namespace decls are not collected, as they + /// contribute large part of the index, and they are less useful compared + /// with other decls. RefKind RefFilter = RefKind::Unknown; /// If set to true, SymbolCollector will collect all refs (from main file /// and included headers); otherwise, only refs from main file will be Index: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp =================================================================== --- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp +++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp @@ -367,7 +367,7 @@ return true; if (!shouldCollectSymbol(*ND, *ASTCtx, Opts)) return true; - if (CollectRef && + if (CollectRef && !isa(ND) && (Opts.RefsInHeaders || SM.getFileID(SpellingLoc) == SM.getMainFileID())) DeclRefs[ND].emplace_back(SpellingLoc, Roles); // Don't continue indexing if this is a mere reference. Index: clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp +++ clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp @@ -443,6 +443,8 @@ }; class $bar[[Bar]]; void $func[[func]](); + + namespace $ns[[NS]] {} // namespace ref is ignored )"); Annotations Main(R"( class $bar[[Bar]] {}; @@ -474,6 +476,7 @@ HaveRanges(Main.ranges("bar"))))); EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "func").ID, HaveRanges(Main.ranges("func"))))); + EXPECT_THAT(Refs, Not(Contains(Pair(findSymbol(Symbols, "NS").ID, _)))); // Symbols *only* in the main file (a, b, c) had no refs collected. auto MainSymbols = TestTU::withHeaderCode(SymbolsOnlyInMainCode.code()).headerSymbols();