diff --git a/crates/ide/src/call_hierarchy.rs b/crates/ide/src/call_hierarchy.rs index 5a8cda8fb3..1506e44a71 100644 --- a/crates/ide/src/call_hierarchy.rs +++ b/crates/ide/src/call_hierarchy.rs @@ -57,7 +57,8 @@ pub(crate) fn incoming_calls( .flat_map(|func| func.usages(sema).all()); for (_, references) in references { - let references = references.into_iter().map(|FileReference { name, .. }| name); + let references = + references.iter().filter_map(|FileReference { name, .. }| name.as_name_ref()); for name in references { // This target is the containing function let nav = sema.ancestors_with_macros(name.syntax().clone()).find_map(|node| { @@ -457,4 +458,148 @@ fn caller$0() { expect![[]], ); } + + #[test] + fn test_trait_method_call_hierarchy_on_def() { + check_hierarchy( + r#" +trait T1 { + fn call$0ee(); +} + +struct S1; + +impl T1 for S1 { + fn callee() {} +} + +fn caller() { + S1::callee(); +} +"#, + expect![["callee Function FileId(0) 15..27 18..24"]], + expect![["caller Function FileId(0) 82..115 85..91 : [104..110]"]], + expect![[]], + ); + } + + #[test] + fn test_trait_method_call_hierarchy_on_impl() { + check_hierarchy( + r#" +trait T1 { + fn callee(); +} + +struct S1; + +impl T1 for S1 { + fn call$0ee() {} +} + +fn caller() { + S1::callee(); +} +"#, + expect![["callee Function FileId(0) 64..78 67..73"]], + expect![["caller Function FileId(0) 82..115 85..91 : [104..110]"]], + expect![[]], + ); + } + + #[test] + fn test_trait_method_call_hierarchy_on_ref() { + check_hierarchy( + r#" +trait T1 { + fn callee(); +} + +struct S1; + +impl T1 for S1 { + fn callee() {} +} + +fn caller() { + S1::call$0ee(); +} +"#, + expect![["callee Function FileId(0) 64..78 67..73"]], + expect![["caller Function FileId(0) 82..115 85..91 : [104..110]"]], + expect![[]], + ); + } + + #[test] + fn test_trait_method_generic_call_hierarchy_on_def() { + check_hierarchy( + r#" +trait T1 { + fn call$0ee(); +} + +struct S1; + +impl T1 for S1 { + fn callee() {} +} + +fn caller() { + T::callee(); +} +"#, + expect![["callee Function FileId(0) 15..27 18..24"]], + expect![["caller Function FileId(0) 82..121 85..91 : [110..116]"]], + expect![[]], + ); + } + + #[test] + fn test_trait_method_generic_call_hierarchy_on_impl() { + check_hierarchy( + r#" +trait T1 { + fn callee(); +} + +struct S1; + +impl T1 for S1 { + fn call$0ee() {} +} + +fn caller() { + T::callee(); +} +"#, + expect![["callee Function FileId(0) 64..78 67..73"]], + expect![["caller Function FileId(0) 82..121 85..91 : [110..116]"]], + expect![[]], + ); + } + + #[test] + fn test_trait_method_generic_call_hierarchy_on_ref() { + check_hierarchy( + r#" +trait T1 { + fn callee(); +} + +struct S1; + +impl T1 for S1 { + fn callee() {} +} + +fn caller() { + T::call$0ee(); +} +"#, + expect![["callee Function FileId(0) 15..27 18..24"]], + expect![["caller Function FileId(0) 82..121 85..91 : [110..116]"]], + expect![[]], + ); + } }