@@ -446,6 +446,51 @@ TEST(CallHierarchy, CallInLocalVarDecl) {
446
446
AllOf (from (withName (" caller3" )), fromRanges (Source.range (" call3" )))));
447
447
}
448
448
449
+ TEST (CallHierarchy, HierarchyOnField) {
450
+ // Tests that the call hierarchy works on fields.
451
+ Annotations Source (R"cpp(
452
+ struct Vars {
453
+ int v^ar1 = 1;
454
+ };
455
+ void caller() {
456
+ Vars values;
457
+ values.$Callee[[var1]];
458
+ }
459
+ )cpp" );
460
+ TestTU TU = TestTU::withCode (Source.code ());
461
+ auto AST = TU.build ();
462
+ auto Index = TU.index ();
463
+
464
+ std::vector<CallHierarchyItem> Items =
465
+ prepareCallHierarchy (AST, Source.point (), testPath (TU.Filename ));
466
+ ASSERT_THAT (Items, ElementsAre (withName (" var1" )));
467
+ auto IncomingLevel1 = incomingCalls (Items[0 ], Index.get ());
468
+ ASSERT_THAT (IncomingLevel1,
469
+ ElementsAre (AllOf (from (withName (" caller" )),
470
+ fromRanges (Source.range (" Callee" )))));
471
+ }
472
+
473
+ TEST (CallHierarchy, HierarchyOnVar) {
474
+ // Tests that the call hierarchy works on non-local variables.
475
+ Annotations Source (R"cpp(
476
+ int v^ar = 1;
477
+ void caller() {
478
+ $Callee[[var]];
479
+ }
480
+ )cpp" );
481
+ TestTU TU = TestTU::withCode (Source.code ());
482
+ auto AST = TU.build ();
483
+ auto Index = TU.index ();
484
+
485
+ std::vector<CallHierarchyItem> Items =
486
+ prepareCallHierarchy (AST, Source.point (), testPath (TU.Filename ));
487
+ ASSERT_THAT (Items, ElementsAre (withName (" var" )));
488
+ auto IncomingLevel1 = incomingCalls (Items[0 ], Index.get ());
489
+ ASSERT_THAT (IncomingLevel1,
490
+ ElementsAre (AllOf (from (withName (" caller" )),
491
+ fromRanges (Source.range (" Callee" )))));
492
+ }
493
+
449
494
} // namespace
450
495
} // namespace clangd
451
496
} // namespace clang
0 commit comments