Commit a133cbaa authored by Haojian Wu's avatar Haojian Wu
Browse files

[clang][index] Index the injected class name types.

Summary: Currently, we (clangd) are missing this kind of references.

Reviewers: kadircet

Subscribers: ilya-biryukov, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73109
parent de51559f
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -170,6 +170,11 @@ public:
    return true;
  }

  bool VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
    return IndexCtx.handleReference(TL.getDecl(), TL.getNameLoc(), Parent,
                                    ParentDC, SymbolRoleSet(), Relations);
  }

  bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
    const DependentNameType *DNT = TL.getTypePtr();
    const NestedNameSpecifier *NNS = DNT->getQualifier();
+21 −0
Original line number Diff line number Diff line
@@ -293,6 +293,27 @@ TEST(IndexTest, Constructors) {
                WrittenAt(Position(4, 8)))));
}

TEST(IndexTest, InjecatedNameClass) {
  std::string Code = R"cpp(
    template <typename T>
    class Foo {
      void f(Foo x);
    };
  )cpp";
  auto Index = std::make_shared<Indexer>();
  IndexingOptions Opts;
  tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
  EXPECT_THAT(Index->Symbols,
              UnorderedElementsAre(AllOf(QName("Foo"), Kind(SymbolKind::Class),
                                         WrittenAt(Position(3, 11))),
                                   AllOf(QName("Foo::f"),
                                         Kind(SymbolKind::InstanceMethod),
                                         WrittenAt(Position(4, 12))),
                                   AllOf(QName("Foo"), Kind(SymbolKind::Class),
                                         HasRole(SymbolRole::Reference),
                                         WrittenAt(Position(4, 14)))));
}

} // namespace
} // namespace index
} // namespace clang