Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions crates/ra_ide/src/call_hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]"],
&[],
);
}
}
4 changes: 2 additions & 2 deletions crates/rust-analyzer/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)? {
Expand Down Expand Up @@ -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)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if that means that our API and/or protocol are off. Positions only make sense for the first request which initializes call hierarchy. Navingating to incoming/outgoing call should not use positions. At the same time, round-tripping some kind of persistent cookies seems awkward.

I guess, for the time being this is a fine fix, but this needs more design long-term.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of reconstructing the call item and passing that down and may try something like that in a followup PR.

let fpos = FilePosition { file_id: frange.file_id, offset: frange.range.start() };

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