aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Kolb <[email protected]>2020-06-28 19:43:02 +0100
committerkjeremy <[email protected]>2020-07-01 12:56:15 +0100
commit20d864807d839e5365cbbc1d0fbf79ef3e691831 (patch)
tree7a1f2b51b8057d70716659432b50bd732c9cffe8
parent248b656c2178a69955c56a48eb44b3cd59b634bb (diff)
Use the selection range when resolving call hierarchy items
Add a test in call_hierarchy that already passed Fixes #5103
-rw-r--r--crates/ra_ide/src/call_hierarchy.rs37
-rw-r--r--crates/rust-analyzer/src/handlers.rs4
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 1e3a31602..bd0e48834 100644
--- a/crates/ra_ide/src/call_hierarchy.rs
+++ b/crates/ra_ide/src/call_hierarchy.rs
@@ -355,4 +355,41 @@ fn caller3() {
355 &["caller3 FN_DEF FileId(1) 66..83 69..76 : [52..59]"], 355 &["caller3 FN_DEF FileId(1) 66..83 69..76 : [52..59]"],
356 ); 356 );
357 } 357 }
358
359 #[test]
360 fn test_call_hierarchy_issue_5103() {
361 check_hierarchy(
362 r#"
363fn a() {
364 b()
365}
366
367fn b() {}
368
369fn main() {
370 a<|>()
371}
372"#,
373 "a FN_DEF FileId(1) 0..18 3..4",
374 &["main FN_DEF FileId(1) 31..52 34..38 : [47..48]"],
375 &["b FN_DEF FileId(1) 20..29 23..24 : [13..14]"],
376 );
377
378 check_hierarchy(
379 r#"
380fn a() {
381 b<|>()
382}
383
384fn b() {}
385
386fn main() {
387 a()
388}
389"#,
390 "b FN_DEF FileId(1) 20..29 23..24",
391 &["a FN_DEF FileId(1) 0..18 3..4 : [13..14]"],
392 &[],
393 );
394 }
358} 395}
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 607a95682..3cb532b62 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(
1045 let item = params.item; 1045 let item = params.item;
1046 1046
1047 let doc = TextDocumentIdentifier::new(item.uri); 1047 let doc = TextDocumentIdentifier::new(item.uri);
1048 let frange = from_proto::file_range(&snap, doc, item.range)?; 1048 let frange = from_proto::file_range(&snap, doc, item.selection_range)?;
1049 let fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() }; 1049 let fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() };
1050 1050
1051 let call_items = match snap.analysis.incoming_calls(fpos)? { 1051 let call_items = match snap.analysis.incoming_calls(fpos)? {
@@ -1080,7 +1080,7 @@ pub(crate) fn handle_call_hierarchy_outgoing(
1080 let item = params.item; 1080 let item = params.item;
1081 1081
1082 let doc = TextDocumentIdentifier::new(item.uri); 1082 let doc = TextDocumentIdentifier::new(item.uri);
1083 let frange = from_proto::file_range(&snap, doc, item.range)?; 1083 let frange = from_proto::file_range(&snap, doc, item.selection_range)?;
1084 let fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() }; 1084 let fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() };
1085 1085
1086 let call_items = match snap.analysis.outgoing_calls(fpos)? { 1086 let call_items = match snap.analysis.outgoing_calls(fpos)? {