[clang-tools-extra] 5b6f475 - [clangd] Sort results of incomingCalls request by container name
Nathan Ridge via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 24 00:29:32 PST 2020
Author: Nathan Ridge
Date: 2020-11-24T03:29:02-05:00
New Revision: 5b6f47595bab686c6c3351fc1bd1f564add80dbf
URL: https://github.com/llvm/llvm-project/commit/5b6f47595bab686c6c3351fc1bd1f564add80dbf
DIFF: https://github.com/llvm/llvm-project/commit/5b6f47595bab686c6c3351fc1bd1f564add80dbf.diff
LOG: [clangd] Sort results of incomingCalls request by container name
Differential Revision: https://reviews.llvm.org/D92009
Added:
Modified:
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index e319636f9076..31e963cb853f 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1716,6 +1716,11 @@ incomingCalls(const CallHierarchyItem &Item, const SymbolIndex *Index) {
Results.push_back(
CallHierarchyIncomingCall{std::move(*CHI), std::move(It->second)});
});
+ // Sort results by name of container.
+ llvm::sort(Results, [](const CallHierarchyIncomingCall &A,
+ const CallHierarchyIncomingCall &B) {
+ return A.from.name < B.from.name;
+ });
return Results;
}
diff --git a/clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp b/clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
index ce192466b442..8b5069d8dae8 100644
--- a/clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CallHierarchyTests.cpp
@@ -31,6 +31,7 @@ namespace {
using ::testing::AllOf;
using ::testing::ElementsAre;
using ::testing::Field;
+using ::testing::IsEmpty;
using ::testing::Matcher;
using ::testing::UnorderedElementsAre;
@@ -69,27 +70,27 @@ TEST(CallHierarchy, IncomingOneFile) {
std::vector<CallHierarchyItem> Items =
prepareCallHierarchy(AST, Source.point(), testPath(TU.Filename));
- EXPECT_THAT(Items, ElementsAre(WithName("callee")));
+ ASSERT_THAT(Items, ElementsAre(WithName("callee")));
auto IncomingLevel1 = incomingCalls(Items[0], Index.get());
- EXPECT_THAT(IncomingLevel1,
+ ASSERT_THAT(IncomingLevel1,
ElementsAre(AllOf(From(WithName("caller1")),
FromRanges(Source.range("Callee")))));
auto IncomingLevel2 = incomingCalls(IncomingLevel1[0].from, Index.get());
- EXPECT_THAT(IncomingLevel2, UnorderedElementsAre(
- AllOf(From(WithName("caller2")),
- FromRanges(Source.range("Caller1A"),
- Source.range("Caller1B"))),
- AllOf(From(WithName("caller3")),
- FromRanges(Source.range("Caller1C")))));
+ ASSERT_THAT(IncomingLevel2,
+ ElementsAre(AllOf(From(WithName("caller2")),
+ FromRanges(Source.range("Caller1A"),
+ Source.range("Caller1B"))),
+ AllOf(From(WithName("caller3")),
+ FromRanges(Source.range("Caller1C")))));
auto IncomingLevel3 = incomingCalls(IncomingLevel2[0].from, Index.get());
- EXPECT_THAT(IncomingLevel3,
+ ASSERT_THAT(IncomingLevel3,
ElementsAre(AllOf(From(WithName("caller3")),
FromRanges(Source.range("Caller2")))));
auto IncomingLevel4 = incomingCalls(IncomingLevel3[0].from, Index.get());
- EXPECT_THAT(IncomingLevel4, ElementsAre());
+ EXPECT_THAT(IncomingLevel4, IsEmpty());
}
TEST(CallHierarchy, MainFileOnlyRef) {
@@ -113,16 +114,16 @@ TEST(CallHierarchy, MainFileOnlyRef) {
std::vector<CallHierarchyItem> Items =
prepareCallHierarchy(AST, Source.point(), testPath(TU.Filename));
- EXPECT_THAT(Items, ElementsAre(WithName("callee")));
+ ASSERT_THAT(Items, ElementsAre(WithName("callee")));
auto IncomingLevel1 = incomingCalls(Items[0], Index.get());
- EXPECT_THAT(IncomingLevel1,
+ ASSERT_THAT(IncomingLevel1,
ElementsAre(AllOf(From(WithName("caller1")),
FromRanges(Source.range("Callee")))));
auto IncomingLevel2 = incomingCalls(IncomingLevel1[0].from, Index.get());
EXPECT_THAT(IncomingLevel2,
- UnorderedElementsAre(AllOf(From(WithName("caller2")),
- FromRanges(Source.range("Caller1")))));
+ ElementsAre(AllOf(From(WithName("caller2")),
+ FromRanges(Source.range("Caller1")))));
}
TEST(CallHierarchy, IncomingQualified) {
@@ -146,13 +147,13 @@ TEST(CallHierarchy, IncomingQualified) {
std::vector<CallHierarchyItem> Items =
prepareCallHierarchy(AST, Source.point(), testPath(TU.Filename));
- EXPECT_THAT(Items, ElementsAre(WithName("Waldo::find")));
+ ASSERT_THAT(Items, ElementsAre(WithName("Waldo::find")));
auto Incoming = incomingCalls(Items[0], Index.get());
EXPECT_THAT(Incoming,
- UnorderedElementsAre(AllOf(From(WithName("caller1")),
- FromRanges(Source.range("Caller1"))),
- AllOf(From(WithName("caller2")),
- FromRanges(Source.range("Caller2")))));
+ ElementsAre(AllOf(From(WithName("caller1")),
+ FromRanges(Source.range("Caller1"))),
+ AllOf(From(WithName("caller2")),
+ FromRanges(Source.range("Caller2")))));
}
TEST(CallHierarchy, IncomingMultiFile) {
@@ -212,27 +213,27 @@ TEST(CallHierarchy, IncomingMultiFile) {
auto CheckCallHierarchy = [&](ParsedAST &AST, Position Pos, PathRef TUPath) {
std::vector<CallHierarchyItem> Items =
prepareCallHierarchy(AST, Pos, TUPath);
- EXPECT_THAT(Items, ElementsAre(WithName("callee")));
+ ASSERT_THAT(Items, ElementsAre(WithName("callee")));
auto IncomingLevel1 = incomingCalls(Items[0], Index.get());
- EXPECT_THAT(IncomingLevel1,
+ ASSERT_THAT(IncomingLevel1,
ElementsAre(AllOf(From(WithName("caller1")),
FromRanges(Caller1C.range()))));
auto IncomingLevel2 = incomingCalls(IncomingLevel1[0].from, Index.get());
- EXPECT_THAT(IncomingLevel2,
- UnorderedElementsAre(
- AllOf(From(WithName("caller2")),
+ ASSERT_THAT(
+ IncomingLevel2,
+ ElementsAre(AllOf(From(WithName("caller2")),
FromRanges(Caller2C.range("A"), Caller2C.range("B"))),
AllOf(From(WithName("caller3")),
FromRanges(Caller3C.range("Caller1")))));
auto IncomingLevel3 = incomingCalls(IncomingLevel2[0].from, Index.get());
- EXPECT_THAT(IncomingLevel3,
+ ASSERT_THAT(IncomingLevel3,
ElementsAre(AllOf(From(WithName("caller3")),
FromRanges(Caller3C.range("Caller2")))));
auto IncomingLevel4 = incomingCalls(IncomingLevel3[0].from, Index.get());
- EXPECT_THAT(IncomingLevel4, ElementsAre());
+ EXPECT_THAT(IncomingLevel4, IsEmpty());
};
// Check that invoking from a call site works.
More information about the cfe-commits
mailing list