aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_def/src/nameres/collector.rs1
-rw-r--r--crates/ide/src/hover.rs29
-rw-r--r--crates/rust-analyzer/src/config.rs4
-rw-r--r--crates/rust-analyzer/src/handlers.rs31
-rw-r--r--docs/user/generated_config.adoc6
-rw-r--r--editors/code/package.json5
-rw-r--r--editors/code/src/config.ts1
7 files changed, 76 insertions, 1 deletions
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs
index b2ce739bd..d0b1db5d1 100644
--- a/crates/hir_def/src/nameres/collector.rs
+++ b/crates/hir_def/src/nameres/collector.rs
@@ -1062,6 +1062,7 @@ impl DefCollector<'_> {
1062 .collect(&[*mod_item]); 1062 .collect(&[*mod_item]);
1063 1063
1064 // Remove the original directive since we resolved it. 1064 // Remove the original directive since we resolved it.
1065 res = ReachedFixedPoint::No;
1065 return false; 1066 return false;
1066 } 1067 }
1067 } 1068 }
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 573ffd10d..ed4f18e1f 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -34,6 +34,7 @@ use crate::{
34#[derive(Clone, Debug, PartialEq, Eq)] 34#[derive(Clone, Debug, PartialEq, Eq)]
35pub struct HoverConfig { 35pub struct HoverConfig {
36 pub implementations: bool, 36 pub implementations: bool,
37 pub references: bool,
37 pub run: bool, 38 pub run: bool,
38 pub debug: bool, 39 pub debug: bool,
39 pub goto_type_def: bool, 40 pub goto_type_def: bool,
@@ -44,6 +45,7 @@ pub struct HoverConfig {
44impl HoverConfig { 45impl HoverConfig {
45 pub const NO_ACTIONS: Self = Self { 46 pub const NO_ACTIONS: Self = Self {
46 implementations: false, 47 implementations: false,
48 references: false,
47 run: false, 49 run: false,
48 debug: false, 50 debug: false,
49 goto_type_def: false, 51 goto_type_def: false,
@@ -52,7 +54,7 @@ impl HoverConfig {
52 }; 54 };
53 55
54 pub fn any(&self) -> bool { 56 pub fn any(&self) -> bool {
55 self.implementations || self.runnable() || self.goto_type_def 57 self.implementations || self.references || self.runnable() || self.goto_type_def
56 } 58 }
57 59
58 pub fn none(&self) -> bool { 60 pub fn none(&self) -> bool {
@@ -68,6 +70,7 @@ impl HoverConfig {
68pub enum HoverAction { 70pub enum HoverAction {
69 Runnable(Runnable), 71 Runnable(Runnable),
70 Implementation(FilePosition), 72 Implementation(FilePosition),
73 Reference(FilePosition),
71 GoToType(Vec<HoverGotoTypeData>), 74 GoToType(Vec<HoverGotoTypeData>),
72} 75}
73 76
@@ -159,6 +162,10 @@ pub(crate) fn hover(
159 res.actions.push(action); 162 res.actions.push(action);
160 } 163 }
161 164
165 if let Some(action) = show_fn_references_action(db, definition) {
166 res.actions.push(action);
167 }
168
162 if let Some(action) = runnable_action(&sema, definition, position.file_id) { 169 if let Some(action) = runnable_action(&sema, definition, position.file_id) {
163 res.actions.push(action); 170 res.actions.push(action);
164 } 171 }
@@ -262,6 +269,18 @@ fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<Hov
262 adt.try_to_nav(db).map(to_action) 269 adt.try_to_nav(db).map(to_action)
263} 270}
264 271
272fn show_fn_references_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
273 match def {
274 Definition::ModuleDef(ModuleDef::Function(it)) => it.try_to_nav(db).map(|nav_target| {
275 HoverAction::Reference(FilePosition {
276 file_id: nav_target.file_id,
277 offset: nav_target.focus_or_full_range().start(),
278 })
279 }),
280 _ => None,
281 }
282}
283
265fn runnable_action( 284fn runnable_action(
266 sema: &Semantics<RootDatabase>, 285 sema: &Semantics<RootDatabase>,
267 def: Definition, 286 def: Definition,
@@ -2428,6 +2447,14 @@ fn foo_$0test() {}
2428"#, 2447"#,
2429 expect![[r#" 2448 expect![[r#"
2430 [ 2449 [
2450 Reference(
2451 FilePosition {
2452 file_id: FileId(
2453 0,
2454 ),
2455 offset: 11,
2456 },
2457 ),
2431 Runnable( 2458 Runnable(
2432 Runnable { 2459 Runnable {
2433 nav: NavigationTarget { 2460 nav: NavigationTarget {
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 })
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc
index 4eec8455d..34a91486b 100644
--- a/docs/user/generated_config.adoc
+++ b/docs/user/generated_config.adoc
@@ -228,6 +228,12 @@ Whether to show `Go to Type Definition` action. Only applies when
228Whether to show `Implementations` action. Only applies when 228Whether to show `Implementations` action. Only applies when
229`#rust-analyzer.hoverActions.enable#` is set. 229`#rust-analyzer.hoverActions.enable#` is set.
230-- 230--
231[[rust-analyzer.hoverActions.references]]rust-analyzer.hoverActions.references (default: `false`)::
232+
233--
234Whether to show `References` action. Only applies when
235`#rust-analyzer.hoverActions.enable#` is set.
236--
231[[rust-analyzer.hoverActions.run]]rust-analyzer.hoverActions.run (default: `true`):: 237[[rust-analyzer.hoverActions.run]]rust-analyzer.hoverActions.run (default: `true`)::
232+ 238+
233-- 239--
diff --git a/editors/code/package.json b/editors/code/package.json
index bffc1e05b..0f3ed48a0 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -660,6 +660,11 @@
660 "default": true, 660 "default": true,
661 "type": "boolean" 661 "type": "boolean"
662 }, 662 },
663 "rust-analyzer.hoverActions.references": {
664 "markdownDescription": "Whether to show `References` action. Only applies when\n`#rust-analyzer.hoverActions.enable#` is set.",
665 "default": false,
666 "type": "boolean"
667 },
663 "rust-analyzer.hoverActions.run": { 668 "rust-analyzer.hoverActions.run": {
664 "markdownDescription": "Whether to show `Run` action. Only applies when\n`#rust-analyzer.hoverActions.enable#` is set.", 669 "markdownDescription": "Whether to show `Run` action. Only applies when\n`#rust-analyzer.hoverActions.enable#` is set.",
665 "default": true, 670 "default": true,
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts
index d3d6e631a..1f1fe59a4 100644
--- a/editors/code/src/config.ts
+++ b/editors/code/src/config.ts
@@ -165,6 +165,7 @@ export class Config {
165 return { 165 return {
166 enable: this.get<boolean>("hoverActions.enable"), 166 enable: this.get<boolean>("hoverActions.enable"),
167 implementations: this.get<boolean>("hoverActions.implementations"), 167 implementations: this.get<boolean>("hoverActions.implementations"),
168 references: this.get<boolean>("hoverActions.references"),
168 run: this.get<boolean>("hoverActions.run"), 169 run: this.get<boolean>("hoverActions.run"),
169 debug: this.get<boolean>("hoverActions.debug"), 170 debug: this.get<boolean>("hoverActions.debug"),
170 gotoTypeDef: this.get<boolean>("hoverActions.gotoTypeDef"), 171 gotoTypeDef: this.get<boolean>("hoverActions.gotoTypeDef"),