Skip to content

Commit e21ddbd

Browse files
timon-ulkrishna2803
authored andcommitted
[clangd] Support invoking call hierarchy on enum constants (llvm#147042)
Fixes clangd/clangd#2203
1 parent 1c174cc commit e21ddbd

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2287,7 +2287,8 @@ prepareCallHierarchy(ParsedAST &AST, Position Pos, PathRef TUPath) {
22872287
Decl->getKind() != Decl::Kind::FunctionTemplate &&
22882288
!(Decl->getKind() == Decl::Kind::Var &&
22892289
!cast<VarDecl>(Decl)->isLocalVarDecl()) &&
2290-
Decl->getKind() != Decl::Kind::Field)
2290+
Decl->getKind() != Decl::Kind::Field &&
2291+
Decl->getKind() != Decl::Kind::EnumConstant)
22912292
continue;
22922293
if (auto CHI = declToCallHierarchyItem(*Decl, AST.tuPath()))
22932294
Result.emplace_back(std::move(*CHI));

clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,35 @@ TEST(CallHierarchy, HierarchyOnVar) {
633633
iFromRanges(Source.range("Callee")))));
634634
}
635635

636+
TEST(CallHierarchy, HierarchyOnEnumConstant) {
637+
// Tests that the call hierarchy works on enum constants.
638+
Annotations Source(R"cpp(
639+
enum class Coin { heads$Heads^ , tai$Tails^ls };
640+
void caller() {
641+
Coin::$CallerH[[heads]];
642+
Coin::$CallerT[[tails]];
643+
}
644+
)cpp");
645+
TestTU TU = TestTU::withCode(Source.code());
646+
auto AST = TU.build();
647+
auto Index = TU.index();
648+
649+
std::vector<CallHierarchyItem> Items =
650+
prepareCallHierarchy(AST, Source.point("Heads"), testPath(TU.Filename));
651+
ASSERT_THAT(Items, ElementsAre(withName("heads")));
652+
auto IncomingLevel1 = incomingCalls(Items[0], Index.get());
653+
ASSERT_THAT(IncomingLevel1,
654+
ElementsAre(AllOf(from(withName("caller")),
655+
iFromRanges(Source.range("CallerH")))));
656+
Items =
657+
prepareCallHierarchy(AST, Source.point("Tails"), testPath(TU.Filename));
658+
ASSERT_THAT(Items, ElementsAre(withName("tails")));
659+
IncomingLevel1 = incomingCalls(Items[0], Index.get());
660+
ASSERT_THAT(IncomingLevel1,
661+
ElementsAre(AllOf(from(withName("caller")),
662+
iFromRanges(Source.range("CallerT")))));
663+
}
664+
636665
TEST(CallHierarchy, CallInDifferentFileThanCaller) {
637666
Annotations Header(R"cpp(
638667
#define WALDO void caller() {

0 commit comments

Comments
 (0)