From 20d864807d839e5365cbbc1d0fbf79ef3e691831 Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Sun, 28 Jun 2020 14:43:02 -0400 Subject: [PATCH] Use the selection range when resolving call hierarchy items Add a test in call_hierarchy that already passed Fixes #5103 --- crates/ra_ide/src/call_hierarchy.rs | 37 ++++++++++++++++++++++++++++ crates/rust-analyzer/src/handlers.rs | 4 +-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/crates/ra_ide/src/call_hierarchy.rs b/crates/ra_ide/src/call_hierarchy.rs index 1e3a31602c7..bd0e4883405 100644 --- a/crates/ra_ide/src/call_hierarchy.rs +++ b/crates/ra_ide/src/call_hierarchy.rs @@ -355,4 +355,41 @@ fn caller3() { &["caller3 FN_DEF FileId(1) 66..83 69..76 : [52..59]"], ); } + + #[test] + fn test_call_hierarchy_issue_5103() { + check_hierarchy( + r#" +fn a() { + b() +} + +fn b() {} + +fn main() { + a<|>() +} +"#, + "a FN_DEF FileId(1) 0..18 3..4", + &["main FN_DEF FileId(1) 31..52 34..38 : [47..48]"], + &["b FN_DEF FileId(1) 20..29 23..24 : [13..14]"], + ); + + check_hierarchy( + r#" +fn a() { + b<|>() +} + +fn b() {} + +fn main() { + a() +} +"#, + "b FN_DEF FileId(1) 20..29 23..24", + &["a FN_DEF FileId(1) 0..18 3..4 : [13..14]"], + &[], + ); + } } diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 607a95682a7..3cb532b62b0 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -1045,7 +1045,7 @@ pub(crate) fn handle_call_hierarchy_incoming( let item = params.item; let doc = TextDocumentIdentifier::new(item.uri); - let frange = from_proto::file_range(&snap, doc, item.range)?; + let frange = from_proto::file_range(&snap, doc, item.selection_range)?; let fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() }; let call_items = match snap.analysis.incoming_calls(fpos)? { @@ -1080,7 +1080,7 @@ pub(crate) fn handle_call_hierarchy_outgoing( let item = params.item; let doc = TextDocumentIdentifier::new(item.uri); - let frange = from_proto::file_range(&snap, doc, item.range)?; + let frange = from_proto::file_range(&snap, doc, item.selection_range)?; let fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() }; let call_items = match snap.analysis.outgoing_calls(fpos)? {