Skip to content

Commit 82618aa

Browse files
fix: Emit refs for class & alias templates (#157)
1 parent 0df612e commit 82618aa

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

indexer/Indexer.cc

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -550,14 +550,25 @@ void TuIndexer::saveTemplateSpecializationTypeLoc(
550550
using Kind = clang::TemplateName::NameKind;
551551
switch (templateName.getKind()) {
552552
case Kind::Template: {
553-
if (auto *templateTemplateParmDecl =
554-
llvm::dyn_cast<clang::TemplateTemplateParmDecl>(
555-
templateName.getAsTemplateDecl())) {
556-
if (auto optSymbol = this->symbolFormatter.getTemplateTemplateParmSymbol(
557-
*templateTemplateParmDecl)) {
558-
this->saveReference(*optSymbol,
559-
templateSpecializationTypeLoc.getTemplateNameLoc());
560-
}
553+
auto *templateDecl = templateName.getAsTemplateDecl();
554+
std::optional<std::string_view> optSymbol;
555+
if (auto *classTemplateDecl =
556+
llvm::dyn_cast<clang::ClassTemplateDecl>(templateDecl)) {
557+
optSymbol = this->symbolFormatter.getRecordSymbol(
558+
*classTemplateDecl->getTemplatedDecl());
559+
} else if (auto *typeAliasTemplateDecl =
560+
llvm::dyn_cast<clang::TypeAliasTemplateDecl>(templateDecl)) {
561+
optSymbol = this->symbolFormatter.getTypedefNameSymbol(
562+
*typeAliasTemplateDecl->getTemplatedDecl());
563+
} else if (auto *templateTemplateParmDecl =
564+
llvm::dyn_cast<clang::TemplateTemplateParmDecl>(
565+
templateDecl)) {
566+
optSymbol = this->symbolFormatter.getTemplateTemplateParmSymbol(
567+
*templateTemplateParmDecl);
568+
}
569+
if (optSymbol.has_value()) {
570+
this->saveReference(*optSymbol,
571+
templateSpecializationTypeLoc.getTemplateNameLoc());
561572
}
562573
break;
563574
}

test/index/types/templates.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,13 @@ void specialized(T) {}
3939

4040
template <>
4141
void specialized<int, int>(int) {}
42+
43+
template <typename T>
44+
struct Empty {};
45+
46+
void use_empty() {
47+
Empty<int> x;
48+
Empty<Empty<void>> y;
49+
Empty<PointerType<void *>> z;
50+
RefPtr<int> w;
51+
}

test/index/types/templates.snapshot.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070

7171
using IntRefPtr = RefPtr<int>;
7272
// ^^^^^^^^^ definition [..] IntRefPtr#
73+
// ^^^^^^ reference [..] RefPtr#
7374

7475
template <typename T>
7576
// ^ definition local 14
@@ -86,3 +87,26 @@
8687
template <>
8788
void specialized<int, int>(int) {}
8889
// ^^^^^^^^^^^ definition [..] specialized(d4f767463ce0a6b3).
90+
91+
template <typename T>
92+
// ^ definition local 17
93+
struct Empty {};
94+
// ^^^^^ definition [..] Empty#
95+
96+
void use_empty() {
97+
// ^^^^^^^^^ definition [..] use_empty(49f6e7a06ebc5aa8).
98+
Empty<int> x;
99+
// ^^^^^ reference [..] Empty#
100+
// ^ definition local 18
101+
Empty<Empty<void>> y;
102+
// ^^^^^ reference [..] Empty#
103+
// ^^^^^ reference [..] Empty#
104+
// ^ definition local 19
105+
Empty<PointerType<void *>> z;
106+
// ^^^^^ reference [..] Empty#
107+
// ^^^^^^^^^^^ reference [..] PointerType#
108+
// ^ definition local 20
109+
RefPtr<int> w;
110+
// ^^^^^^ reference [..] RefPtr#
111+
// ^ definition local 21
112+
}

test/index/types/types.snapshot.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146

147147
void f(GenericClass<E, int(E::E0)>) {
148148
// ^ definition [..] f(a9a88f5fb6852c6b).
149+
// ^^^^^^^^^^^^ reference [..] GenericClass#
149150
// ^ reference [..] E#
150151
// ^ reference [..] E#
151152
// ^^ reference [..] E#E0.
@@ -194,6 +195,7 @@
194195
class CRTPChild: CRTPBase<CRTPChild> {
195196
// ^^^^^^^^^ definition [..] CRTPChild#
196197
// relation implementation [..] CRTPBase#
198+
// ^^^^^^^^ reference [..] CRTPBase#
197199
// ^^^^^^^^^ reference [..] CRTPChild#
198200
void doStuff() { }
199201
// ^^^^^^^ definition [..] CRTPChild#doStuff(49f6e7a06ebc5aa8).

0 commit comments

Comments
 (0)