aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/hover.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/hover.rs')
-rw-r--r--crates/ide/src/hover.rs29
1 files changed, 28 insertions, 1 deletions
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 {