diff --git a/clang-tools-extra/clangd/ClangdServer.h b/clang-tools-extra/clangd/ClangdServer.h --- a/clang-tools-extra/clangd/ClangdServer.h +++ b/clang-tools-extra/clangd/ClangdServer.h @@ -106,7 +106,7 @@ bool BackgroundIndex = false; /// Store refs to main-file symbols in the index. - bool CollectMainFileRefs = false; + bool CollectMainFileRefs = true; /// If set, use this index to augment code completion results. SymbolIndex *StaticIndex = nullptr; diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -494,7 +494,7 @@ "collect-main-file-refs", cat(Misc), desc("Store references to main-file-only symbols in the index"), - init(false), + init(ClangdServer::Options().CollectMainFileRefs), }; #if CLANGD_ENABLE_REMOTE diff --git a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp --- a/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp +++ b/clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp @@ -188,8 +188,10 @@ size_t CacheHits = 0; MemoryShardStorage MSS(Storage, CacheHits); OverlayCDB CDB(/*Base=*/nullptr); - BackgroundIndex Idx(FS, CDB, [&](llvm::StringRef) { return &MSS; }, - /*Opts=*/{}); + BackgroundIndex::Options Opts; + Opts.CollectMainFileRefs = true; + BackgroundIndex Idx( + FS, CDB, [&](llvm::StringRef) { return &MSS; }, Opts); tooling::CompileCommand Cmd; Cmd.Filename = testPath("root/A.cc"); @@ -201,7 +203,7 @@ EXPECT_THAT(runFuzzyFind(Idx, ""), UnorderedElementsAre(AllOf(Named("common"), NumReferences(1U)), AllOf(Named("A_CC"), NumReferences(0U)), - AllOf(Named("g"), NumReferences(0U)), + AllOf(Named("g"), NumReferences(1U)), AllOf(Named("f_b"), Declared(), Not(Defined()), NumReferences(0U)))); @@ -214,7 +216,7 @@ EXPECT_THAT(runFuzzyFind(Idx, ""), UnorderedElementsAre(AllOf(Named("common"), NumReferences(5U)), AllOf(Named("A_CC"), NumReferences(0U)), - AllOf(Named("g"), NumReferences(0U)), + AllOf(Named("g"), NumReferences(1U)), AllOf(Named("f_b"), Declared(), Defined(), NumReferences(1U)))); @@ -238,7 +240,8 @@ FS.Files[testPath("root/A.cc")] = "#include \"A.h\"\nstatic void main_sym() { (void)header_sym; }"; - // Check the behaviour with CollectMainFileRefs = false (the default). + // Check the behaviour with CollectMainFileRefs = false (the default + // at the SymbolCollector level). { llvm::StringMap Storage; size_t CacheHits = 0;