Skip to content

Commit a133cba

Browse files
committed
[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
1 parent de51559 commit a133cba

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

clang/lib/Index/IndexTypeSourceInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ class TypeIndexer : public RecursiveASTVisitor<TypeIndexer> {
170170
return true;
171171
}
172172

173+
bool VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) {
174+
return IndexCtx.handleReference(TL.getDecl(), TL.getNameLoc(), Parent,
175+
ParentDC, SymbolRoleSet(), Relations);
176+
}
177+
173178
bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) {
174179
const DependentNameType *DNT = TL.getTypePtr();
175180
const NestedNameSpecifier *NNS = DNT->getQualifier();

clang/unittests/Index/IndexTests.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,27 @@ TEST(IndexTest, Constructors) {
293293
WrittenAt(Position(4, 8)))));
294294
}
295295

296+
TEST(IndexTest, InjecatedNameClass) {
297+
std::string Code = R"cpp(
298+
template <typename T>
299+
class Foo {
300+
void f(Foo x);
301+
};
302+
)cpp";
303+
auto Index = std::make_shared<Indexer>();
304+
IndexingOptions Opts;
305+
tooling::runToolOnCode(std::make_unique<IndexAction>(Index, Opts), Code);
306+
EXPECT_THAT(Index->Symbols,
307+
UnorderedElementsAre(AllOf(QName("Foo"), Kind(SymbolKind::Class),
308+
WrittenAt(Position(3, 11))),
309+
AllOf(QName("Foo::f"),
310+
Kind(SymbolKind::InstanceMethod),
311+
WrittenAt(Position(4, 12))),
312+
AllOf(QName("Foo"), Kind(SymbolKind::Class),
313+
HasRole(SymbolRole::Reference),
314+
WrittenAt(Position(4, 14)))));
315+
}
316+
296317
} // namespace
297318
} // namespace index
298319
} // namespace clang

0 commit comments

Comments
 (0)