Skip to content

Commit ec8b4dc

Browse files
bors[bot]kjeremy
andauthored
Merge #5110
5110: Use the selection range when resolving call hierarchy items r=kjeremy a=kjeremy Add a test in call_hierarchy that already passed and a corresponding heavy test to test the LSP requests which exposed the issue. Fixes #5103 Co-authored-by: Jeremy Kolb <[email protected]>
2 parents 248b656 + 20d8648 commit ec8b4dc

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

crates/ra_ide/src/call_hierarchy.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,4 +355,41 @@ fn caller3() {
355355
&["caller3 FN_DEF FileId(1) 66..83 69..76 : [52..59]"],
356356
);
357357
}
358+
359+
#[test]
360+
fn test_call_hierarchy_issue_5103() {
361+
check_hierarchy(
362+
r#"
363+
fn a() {
364+
b()
365+
}
366+
367+
fn b() {}
368+
369+
fn 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#"
380+
fn a() {
381+
b<|>()
382+
}
383+
384+
fn b() {}
385+
386+
fn 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+
}
358395
}

crates/rust-analyzer/src/handlers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ pub(crate) fn handle_call_hierarchy_incoming(
10451045
let item = params.item;
10461046

10471047
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)?;
10491049
let fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() };
10501050

10511051
let call_items = match snap.analysis.incoming_calls(fpos)? {
@@ -1080,7 +1080,7 @@ pub(crate) fn handle_call_hierarchy_outgoing(
10801080
let item = params.item;
10811081

10821082
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)?;
10841084
let fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() };
10851085

10861086
let call_items = match snap.analysis.outgoing_calls(fpos)? {

0 commit comments

Comments
 (0)