nridge created this revision.
nridge added a reviewer: kadircet.
Herald added subscribers: cfe-commits, usaxena95, arphaman.
Herald added a project: clang.
nridge requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
This is needed for call hierarchy to be able to find callers of
main-file-only functions.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D92000
Files:
clang-tools-extra/clangd/index/Background.h
clang-tools-extra/clangd/index/FileIndex.h
clang-tools-extra/clangd/index/SymbolCollector.h
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -694,6 +694,7 @@
class d {};
)");
CollectorOpts.RefFilter = RefKind::All;
+ CollectorOpts.CollectMainFileRefs = false;
CollectorOpts.CollectMacro = true;
runSymbolCollector(Header.code(),
(Main.code() + SymbolsOnlyInMainCode.code()).str());
@@ -753,7 +754,6 @@
}
)cpp");
CollectorOpts.RefFilter = RefKind::All;
- CollectorOpts.CollectMainFileRefs = true;
runSymbolCollector("", Code.code());
auto FindRefWithRange = [&](Range R) -> Optional<Ref> {
for (auto &Entry : Refs) {
Index: clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
+++ clang-tools-extra/clangd/unittests/BackgroundIndexTests.cpp
@@ -201,7 +201,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 +214,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,14 +238,16 @@
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.
{
llvm::StringMap<std::string> Storage;
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 = false;
+ BackgroundIndex Idx(
+ FS, CDB, [&](llvm::StringRef) { return &MSS; }, Opts);
tooling::CompileCommand Cmd;
Cmd.Filename = testPath("root/A.cc");
@@ -260,16 +262,14 @@
AllOf(Named("main_sym"), NumReferences(0U))));
}
- // Check the behaviour with CollectMainFileRefs = true.
+ // Check the behaviour with CollectMainFileRefs = true (the default).
{
llvm::StringMap<std::string> Storage;
size_t CacheHits = 0;
MemoryShardStorage MSS(Storage, CacheHits);
OverlayCDB CDB(/*Base=*/nullptr);
- BackgroundIndex::Options Opts;
- Opts.CollectMainFileRefs = true;
- BackgroundIndex Idx(
- FS, CDB, [&](llvm::StringRef) { return &MSS; }, Opts);
+ BackgroundIndex Idx(FS, CDB, [&](llvm::StringRef) { return &MSS; },
+ /*Opts=*/{});
tooling::CompileCommand Cmd;
Cmd.Filename = testPath("root/A.cc");
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===================================================================
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -489,7 +489,7 @@
"collect-main-file-refs",
cat(Misc),
desc("Store references to main-file-only symbols in the index"),
- init(false),
+ init(true),
};
#if CLANGD_ENABLE_REMOTE
Index: clang-tools-extra/clangd/index/SymbolCollector.h
===================================================================
--- clang-tools-extra/clangd/index/SymbolCollector.h
+++ clang-tools-extra/clangd/index/SymbolCollector.h
@@ -79,7 +79,7 @@
/// and symbols inside an anonymous namespace.
bool CollectMainFileSymbols = true;
/// Collect references to main-file symbols.
- bool CollectMainFileRefs = false;
+ bool CollectMainFileRefs = true;
/// If set to true, SymbolCollector will collect doc for all symbols.
/// Note that documents of symbols being indexed for completion will always
/// be collected regardless of this option.
Index: clang-tools-extra/clangd/index/FileIndex.h
===================================================================
--- clang-tools-extra/clangd/index/FileIndex.h
+++ clang-tools-extra/clangd/index/FileIndex.h
@@ -107,7 +107,7 @@
/// FIXME: Expose an interface to remove files that are closed.
class FileIndex : public MergedIndex {
public:
- FileIndex(bool UseDex = true, bool CollectMainFileRefs = false);
+ FileIndex(bool UseDex = true, bool CollectMainFileRefs = true);
/// Update preamble symbols of file \p Path with all declarations in \p AST
/// and macros in \p PP.
Index: clang-tools-extra/clangd/index/Background.h
===================================================================
--- clang-tools-extra/clangd/index/Background.h
+++ clang-tools-extra/clangd/index/Background.h
@@ -140,7 +140,7 @@
// (When called, the context from BackgroundIndex construction is active).
std::function<Context(PathRef)> ContextProvider = nullptr;
// Whether to collect references to main-file-only symbols.
- bool CollectMainFileRefs = false;
+ bool CollectMainFileRefs = true;
};
/// Creates a new background index and starts its threads.
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits