@@ -45,6 +45,7 @@ using ::testing::UnorderedElementsAre;
4545// Helpers for matching call hierarchy data structures.
4646MATCHER_P (withName, N, " " ) { return arg.name == N; }
4747MATCHER_P (withDetail, N, " " ) { return arg.detail == N; }
48+ MATCHER_P (withFile, N, " " ) { return arg.uri .file () == N; }
4849MATCHER_P (withSelectionRange, R, " " ) { return arg.selectionRange == R; }
4950
5051template <class ItemMatcher >
@@ -383,18 +384,28 @@ TEST(CallHierarchy, MultiFileCpp) {
383384 EXPECT_THAT (IncomingLevel4, IsEmpty ());
384385 };
385386
386- auto CheckOutgoingCalls = [&](ParsedAST &AST, Position Pos, PathRef TUPath) {
387+ auto CheckOutgoingCalls = [&](ParsedAST &AST, Position Pos, PathRef TUPath,
388+ bool IsDeclaration) {
387389 std::vector<CallHierarchyItem> Items =
388390 prepareCallHierarchy (AST, Pos, TUPath);
389- ASSERT_THAT (Items, ElementsAre (withName (" caller3" )));
391+ ASSERT_THAT (
392+ Items,
393+ ElementsAre (AllOf (
394+ withName (" caller3" ),
395+ withFile (testPath (IsDeclaration ? " caller3.hh" : " caller3.cc" )))));
390396 auto OutgoingLevel1 = outgoingCalls (Items[0 ], Index.get ());
391397 ASSERT_THAT (
392398 OutgoingLevel1,
399+ // fromRanges are interpreted in the context of Items[0]'s file.
400+ // If that's the header, we can't get ranges from the implementation
401+ // file!
393402 ElementsAre (
394403 AllOf (to (AllOf (withName (" caller1" ), withDetail (" nsa::caller1" ))),
395- oFromRanges (Caller3C.range (" Caller1" ))),
404+ IsDeclaration ? oFromRanges ()
405+ : oFromRanges (Caller3C.range (" Caller1" ))),
396406 AllOf (to (AllOf (withName (" caller2" ), withDetail (" nsb::caller2" ))),
397- oFromRanges (Caller3C.range (" Caller2" )))));
407+ IsDeclaration ? oFromRanges ()
408+ : oFromRanges (Caller3C.range (" Caller2" )))));
398409
399410 auto OutgoingLevel2 = outgoingCalls (OutgoingLevel1[1 ].to , Index.get ());
400411 ASSERT_THAT (OutgoingLevel2,
@@ -423,15 +434,15 @@ TEST(CallHierarchy, MultiFileCpp) {
423434 CheckIncomingCalls (*AST, CalleeH.point (), testPath (" callee.hh" ));
424435 AST = Workspace.openFile (" caller3.hh" );
425436 ASSERT_TRUE (bool (AST));
426- CheckOutgoingCalls (*AST, Caller3H.point (), testPath (" caller3.hh" ));
437+ CheckOutgoingCalls (*AST, Caller3H.point (), testPath (" caller3.hh" ), true );
427438
428439 // Check that invoking from the definition site works.
429440 AST = Workspace.openFile (" callee.cc" );
430441 ASSERT_TRUE (bool (AST));
431442 CheckIncomingCalls (*AST, CalleeC.point (), testPath (" callee.cc" ));
432443 AST = Workspace.openFile (" caller3.cc" );
433444 ASSERT_TRUE (bool (AST));
434- CheckOutgoingCalls (*AST, Caller3C.point (), testPath (" caller3.cc" ));
445+ CheckOutgoingCalls (*AST, Caller3C.point (), testPath (" caller3.cc" ), false );
435446}
436447
437448TEST (CallHierarchy, IncomingMultiFileObjC) {
0 commit comments