summaryrefslogtreecommitdiff
path: root/clang-tools-extra/unittests/clangd
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2018-03-12 14:49:09 +0000
committerSam McCall <sam.mccall@gmail.com>2018-03-12 14:49:09 +0000
commit4e9b812af402da7b0177b03b02fe95a2341f2e0b (patch)
treef2663dacd528fbc123bb040df8509eae12133d30 /clang-tools-extra/unittests/clangd
parent8ccff2fdfbfaba29b980777bbaafa748acb1ed94 (diff)
[clangd] Collect the number of files referencing a symbol in the static index.
Summary: This is an important ranking signal. It's off for the dynamic index for now. Correspondingly, tell the index infrastructure only to report declarations for the dynamic index. Reviewers: ioeric, hokein Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D44315
Diffstat (limited to 'clang-tools-extra/unittests/clangd')
-rw-r--r--clang-tools-extra/unittests/clangd/IndexTests.cpp3
-rw-r--r--clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp28
2 files changed, 30 insertions, 1 deletions
diff --git a/clang-tools-extra/unittests/clangd/IndexTests.cpp b/clang-tools-extra/unittests/clangd/IndexTests.cpp
index 20eb4527d9f..5e5ddbfb86e 100644
--- a/clang-tools-extra/unittests/clangd/IndexTests.cpp
+++ b/clang-tools-extra/unittests/clangd/IndexTests.cpp
@@ -225,6 +225,8 @@ TEST(MergeTest, Merge) {
L.Name = R.Name = "Foo"; // same in both
L.CanonicalDeclaration.FileURI = "file:///left.h"; // differs
R.CanonicalDeclaration.FileURI = "file:///right.h";
+ L.References = 1;
+ R.References = 2;
L.CompletionPlainInsertText = "f00"; // present in left only
R.CompletionSnippetInsertText = "f0{$1:0}"; // present in right only
Symbol::Details DetL, DetR;
@@ -238,6 +240,7 @@ TEST(MergeTest, Merge) {
Symbol M = mergeSymbol(L, R, &Scratch);
EXPECT_EQ(M.Name, "Foo");
EXPECT_EQ(M.CanonicalDeclaration.FileURI, "file:///left.h");
+ EXPECT_EQ(M.References, 3u);
EXPECT_EQ(M.CompletionPlainInsertText, "f00");
EXPECT_EQ(M.CompletionSnippetInsertText, "f0{$1:0}");
ASSERT_TRUE(M.Detail);
diff --git a/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp b/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp
index c6a155a4a36..76eace528f4 100644
--- a/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp
@@ -59,6 +59,7 @@ MATCHER_P(DefRange, Offsets, "") {
return arg.Definition.StartOffset == Offsets.first &&
arg.Definition.EndOffset == Offsets.second;
}
+MATCHER_P(Refs, R, "") { return int(arg.References) == R; }
namespace clang {
namespace clangd {
@@ -201,7 +202,7 @@ TEST_F(SymbolCollectorTest, CollectSymbols) {
TEST_F(SymbolCollectorTest, Template) {
Annotations Header(R"(
// Template is indexed, specialization and instantiation is not.
- template <class T> struct [[Tmpl]] {T x = 0};
+ template <class T> struct [[Tmpl]] {T x = 0;};
template <> struct Tmpl<int> {};
extern template struct Tmpl<float>;
template struct Tmpl<double>;
@@ -242,6 +243,31 @@ TEST_F(SymbolCollectorTest, Locations) {
AllOf(QName("Z"), DeclRange(Header.offsetRange("zdecl")))));
}
+TEST_F(SymbolCollectorTest, References) {
+ const std::string Header = R"(
+ class W;
+ class X {};
+ class Y;
+ class Z {}; // not used anywhere
+ Y* y = nullptr; // used in header doesn't count
+ )";
+ const std::string Main = R"(
+ W* w = nullptr;
+ W* w2 = nullptr; // only one usage counts
+ X x();
+ class V;
+ V* v = nullptr; // Used, but not eligible for indexing.
+ class Y{}; // definition doesn't count as a reference
+ )";
+ CollectorOpts.CountReferences = true;
+ runSymbolCollector(Header, Main);
+ EXPECT_THAT(Symbols,
+ UnorderedElementsAre(AllOf(QName("W"), Refs(1)),
+ AllOf(QName("X"), Refs(1)),
+ AllOf(QName("Y"), Refs(0)),
+ AllOf(QName("Z"), Refs(0)), QName("y")));
+}
+
TEST_F(SymbolCollectorTest, SymbolRelativeNoFallback) {
runSymbolCollector("class Foo {};", /*Main=*/"");
EXPECT_THAT(Symbols, UnorderedElementsAre(