-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clangd] Extend call hierarchy for enum constants #147042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clangd Author: None (timon-ul) ChangesImplementation for clangd/clangd#2203 Full diff: https://github.com/llvm/llvm-project/pull/147042.diff 2 Files Affected:
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index 089f8158c9aa5..5bbc681cf04e2 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -2287,7 +2287,8 @@ prepareCallHierarchy(ParsedAST &AST, Position Pos, PathRef TUPath) {
Decl->getKind() != Decl::Kind::FunctionTemplate &&
!(Decl->getKind() == Decl::Kind::Var &&
!cast<VarDecl>(Decl)->isLocalVarDecl()) &&
- Decl->getKind() != Decl::Kind::Field)
+ Decl->getKind() != Decl::Kind::Field &&
+ Decl->getKind() != Decl::Kind::EnumConstant)
continue;
if (auto CHI = declToCallHierarchyItem(*Decl, AST.tuPath()))
Result.emplace_back(std::move(*CHI));
diff --git a/clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp b/clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
index eb852ef5ee00b..08cc80ff8981e 100644
--- a/clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
@@ -633,6 +633,35 @@ TEST(CallHierarchy, HierarchyOnVar) {
iFromRanges(Source.range("Callee")))));
}
+TEST(CallHierarchy, HierarchyOnEnumConstant) {
+ // Tests that the call hierarchy works on enum constants.
+ Annotations Source(R"cpp(
+ enum class Coin { heads$Heads^ , tai$Tails^ls };
+ void caller() {
+ Coin::$CallerH[[heads]];
+ Coin::$CallerT[[tails]];
+ }
+ )cpp");
+ TestTU TU = TestTU::withCode(Source.code());
+ auto AST = TU.build();
+ auto Index = TU.index();
+
+ std::vector<CallHierarchyItem> Items =
+ prepareCallHierarchy(AST, Source.point("Heads"), testPath(TU.Filename));
+ ASSERT_THAT(Items, ElementsAre(withName("heads")));
+ auto IncomingLevel1 = incomingCalls(Items[0], Index.get());
+ ASSERT_THAT(IncomingLevel1,
+ ElementsAre(AllOf(from(withName("caller")),
+ iFromRanges(Source.range("CallerH")))));
+ Items =
+ prepareCallHierarchy(AST, Source.point("Tails"), testPath(TU.Filename));
+ ASSERT_THAT(Items, ElementsAre(withName("tails")));
+ IncomingLevel1 = incomingCalls(Items[0], Index.get());
+ ASSERT_THAT(IncomingLevel1,
+ ElementsAre(AllOf(from(withName("caller")),
+ iFromRanges(Source.range("CallerT")))));
+}
+
TEST(CallHierarchy, CallInDifferentFileThanCaller) {
Annotations Header(R"cpp(
#define WALDO void caller() {
|
@llvm/pr-subscribers-clang-tools-extra Author: None (timon-ul) ChangesImplementation for clangd/clangd#2203 Full diff: https://github.com/llvm/llvm-project/pull/147042.diff 2 Files Affected:
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index 089f8158c9aa5..5bbc681cf04e2 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -2287,7 +2287,8 @@ prepareCallHierarchy(ParsedAST &AST, Position Pos, PathRef TUPath) {
Decl->getKind() != Decl::Kind::FunctionTemplate &&
!(Decl->getKind() == Decl::Kind::Var &&
!cast<VarDecl>(Decl)->isLocalVarDecl()) &&
- Decl->getKind() != Decl::Kind::Field)
+ Decl->getKind() != Decl::Kind::Field &&
+ Decl->getKind() != Decl::Kind::EnumConstant)
continue;
if (auto CHI = declToCallHierarchyItem(*Decl, AST.tuPath()))
Result.emplace_back(std::move(*CHI));
diff --git a/clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp b/clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
index eb852ef5ee00b..08cc80ff8981e 100644
--- a/clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
@@ -633,6 +633,35 @@ TEST(CallHierarchy, HierarchyOnVar) {
iFromRanges(Source.range("Callee")))));
}
+TEST(CallHierarchy, HierarchyOnEnumConstant) {
+ // Tests that the call hierarchy works on enum constants.
+ Annotations Source(R"cpp(
+ enum class Coin { heads$Heads^ , tai$Tails^ls };
+ void caller() {
+ Coin::$CallerH[[heads]];
+ Coin::$CallerT[[tails]];
+ }
+ )cpp");
+ TestTU TU = TestTU::withCode(Source.code());
+ auto AST = TU.build();
+ auto Index = TU.index();
+
+ std::vector<CallHierarchyItem> Items =
+ prepareCallHierarchy(AST, Source.point("Heads"), testPath(TU.Filename));
+ ASSERT_THAT(Items, ElementsAre(withName("heads")));
+ auto IncomingLevel1 = incomingCalls(Items[0], Index.get());
+ ASSERT_THAT(IncomingLevel1,
+ ElementsAre(AllOf(from(withName("caller")),
+ iFromRanges(Source.range("CallerH")))));
+ Items =
+ prepareCallHierarchy(AST, Source.point("Tails"), testPath(TU.Filename));
+ ASSERT_THAT(Items, ElementsAre(withName("tails")));
+ IncomingLevel1 = incomingCalls(Items[0], Index.get());
+ ASSERT_THAT(IncomingLevel1,
+ ElementsAre(AllOf(from(withName("caller")),
+ iFromRanges(Source.range("CallerT")))));
+}
+
TEST(CallHierarchy, CallInDifferentFileThanCaller) {
Annotations Header(R"cpp(
#define WALDO void caller() {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM!
(I've seen the discussion about token selection starting at clangd/clangd#2203 (comment), but haven't had a chance to dig into it and respond yet. Feel free to start a new thread for it to help make sure it doesn't get forgotten.)
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/46/builds/21126 Here is the relevant piece of the build log for the reference
|
Uhm, I am a bit confused, the continuous integration bot reports a failure, but it does not seem related to my changes and also the Pull request still counts as merged and closed. Do I have to worry about this error? |
No, it looks unrelated. Buildbots sometimes run into intermittent test failures that get incorrectly attributed to a PR. |
Implementation for clangd/clangd#2203