aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-06-04 14:49:43 +0100
committerLukas Wirth <[email protected]>2021-06-04 14:54:55 +0100
commit07394316ff0c5454b3a9e854945ebd29b90259ec (patch)
tree43dc7fa25956c233f6a2b3384c134eb48a243a36 /crates/rust-analyzer
parentcd46255d7e8bb59b93a32d5cb50581f418ca5f3b (diff)
Add function references hover action
Diffstat (limited to 'crates/rust-analyzer')
-rw-r--r--crates/rust-analyzer/src/config.rs4
-rw-r--r--crates/rust-analyzer/src/handlers.rs31
2 files changed, 35 insertions, 0 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index d1f3c1b06..3b20d741a 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -152,6 +152,9 @@ config_data! {
152 /// Whether to show `Implementations` action. Only applies when 152 /// Whether to show `Implementations` action. Only applies when
153 /// `#rust-analyzer.hoverActions.enable#` is set. 153 /// `#rust-analyzer.hoverActions.enable#` is set.
154 hoverActions_implementations: bool = "true", 154 hoverActions_implementations: bool = "true",
155 /// Whether to show `References` action. Only applies when
156 /// `#rust-analyzer.hoverActions.enable#` is set.
157 hoverActions_references: bool = "false",
155 /// Whether to show `Run` action. Only applies when 158 /// Whether to show `Run` action. Only applies when
156 /// `#rust-analyzer.hoverActions.enable#` is set. 159 /// `#rust-analyzer.hoverActions.enable#` is set.
157 hoverActions_run: bool = "true", 160 hoverActions_run: bool = "true",
@@ -719,6 +722,7 @@ impl Config {
719 HoverConfig { 722 HoverConfig {
720 implementations: self.data.hoverActions_enable 723 implementations: self.data.hoverActions_enable
721 && self.data.hoverActions_implementations, 724 && self.data.hoverActions_implementations,
725 references: self.data.hoverActions_enable && self.data.hoverActions_references,
722 run: self.data.hoverActions_enable && self.data.hoverActions_run, 726 run: self.data.hoverActions_enable && self.data.hoverActions_run,
723 debug: self.data.hoverActions_enable && self.data.hoverActions_debug, 727 debug: self.data.hoverActions_enable && self.data.hoverActions_debug,
724 goto_type_def: self.data.hoverActions_enable && self.data.hoverActions_gotoTypeDef, 728 goto_type_def: self.data.hoverActions_enable && self.data.hoverActions_gotoTypeDef,
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
1509fn 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
1509fn runnable_action_links( 1539fn 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 })