diff options
Diffstat (limited to 'crates/rust-analyzer/src/handlers.rs')
-rw-r--r-- | crates/rust-analyzer/src/handlers.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 49ee4b922..70511c5ca 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs | |||
@@ -1506,6 +1506,36 @@ fn show_impl_command_link( | |||
1506 | None | 1506 | None |
1507 | } | 1507 | } |
1508 | 1508 | ||
1509 | fn show_ref_command_link( | ||
1510 | snap: &GlobalStateSnapshot, | ||
1511 | position: &FilePosition, | ||
1512 | ) -> Option<lsp_ext::CommandLinkGroup> { | ||
1513 | if snap.config.hover().implementations { | ||
1514 | if let Some(ref_search_res) = snap.analysis.find_all_refs(*position, None).unwrap_or(None) { | ||
1515 | let uri = to_proto::url(snap, position.file_id); | ||
1516 | let line_index = snap.file_line_index(position.file_id).ok()?; | ||
1517 | let position = to_proto::position(&line_index, position.offset); | ||
1518 | let locations: Vec<_> = ref_search_res | ||
1519 | .references | ||
1520 | .into_iter() | ||
1521 | .flat_map(|(file_id, ranges)| { | ||
1522 | ranges.into_iter().filter_map(move |(range, _)| { | ||
1523 | to_proto::location(snap, FileRange { file_id, range }).ok() | ||
1524 | }) | ||
1525 | }) | ||
1526 | .collect(); | ||
1527 | let title = to_proto::reference_title(locations.len()); | ||
1528 | let command = to_proto::command::show_references(title, &uri, position, locations); | ||
1529 | |||
1530 | return Some(lsp_ext::CommandLinkGroup { | ||
1531 | commands: vec![to_command_link(command, "Go to references".into())], | ||
1532 | ..Default::default() | ||
1533 | }); | ||
1534 | } | ||
1535 | } | ||
1536 | None | ||
1537 | } | ||
1538 | |||
1509 | fn runnable_action_links( | 1539 | fn runnable_action_links( |
1510 | snap: &GlobalStateSnapshot, | 1540 | snap: &GlobalStateSnapshot, |
1511 | runnable: Runnable, | 1541 | runnable: Runnable, |
@@ -1566,6 +1596,7 @@ fn prepare_hover_actions( | |||
1566 | .iter() | 1596 | .iter() |
1567 | .filter_map(|it| match it { | 1597 | .filter_map(|it| match it { |
1568 | HoverAction::Implementation(position) => show_impl_command_link(snap, position), | 1598 | HoverAction::Implementation(position) => show_impl_command_link(snap, position), |
1599 | HoverAction::Reference(position) => show_ref_command_link(snap, position), | ||
1569 | HoverAction::Runnable(r) => runnable_action_links(snap, r.clone()), | 1600 | HoverAction::Runnable(r) => runnable_action_links(snap, r.clone()), |
1570 | HoverAction::GoToType(targets) => goto_type_action_links(snap, targets), | 1601 | HoverAction::GoToType(targets) => goto_type_action_links(snap, targets), |
1571 | }) | 1602 | }) |