aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-04 14:55:49 +0100
committerGitHub <[email protected]>2021-06-04 14:55:49 +0100
commitdceec3eb80f3f2d064536ef8272522f65ec1a76c (patch)
tree43dc7fa25956c233f6a2b3384c134eb48a243a36 /crates/ide
parentcd46255d7e8bb59b93a32d5cb50581f418ca5f3b (diff)
parent07394316ff0c5454b3a9e854945ebd29b90259ec (diff)
Merge #9136
9136: feat: Add function references hover action r=Veykril a=Veykril ![image](https://user-images.githubusercontent.com/3757771/120811670-8422ed80-c54c-11eb-87f5-dd65c1f8ef7d.png) This is off by default as this can slow down hover messages significantly for very big projects I believe. Fixes #6590 bors r+ Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide')
-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 04598cd06..455a27e48 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -28,6 +28,7 @@ use crate::{
28#[derive(Clone, Debug, PartialEq, Eq)] 28#[derive(Clone, Debug, PartialEq, Eq)]
29pub struct HoverConfig { 29pub struct HoverConfig {
30 pub implementations: bool, 30 pub implementations: bool,
31 pub references: bool,
31 pub run: bool, 32 pub run: bool,
32 pub debug: bool, 33 pub debug: bool,
33 pub goto_type_def: bool, 34 pub goto_type_def: bool,
@@ -38,6 +39,7 @@ pub struct HoverConfig {
38impl HoverConfig { 39impl HoverConfig {
39 pub const NO_ACTIONS: Self = Self { 40 pub const NO_ACTIONS: Self = Self {
40 implementations: false, 41 implementations: false,
42 references: false,
41 run: false, 43 run: false,
42 debug: false, 44 debug: false,
43 goto_type_def: false, 45 goto_type_def: false,
@@ -46,7 +48,7 @@ impl HoverConfig {
46 }; 48 };
47 49
48 pub fn any(&self) -> bool { 50 pub fn any(&self) -> bool {
49 self.implementations || self.runnable() || self.goto_type_def 51 self.implementations || self.references || self.runnable() || self.goto_type_def
50 } 52 }
51 53
52 pub fn none(&self) -> bool { 54 pub fn none(&self) -> bool {
@@ -62,6 +64,7 @@ impl HoverConfig {
62pub enum HoverAction { 64pub enum HoverAction {
63 Runnable(Runnable), 65 Runnable(Runnable),
64 Implementation(FilePosition), 66 Implementation(FilePosition),
67 Reference(FilePosition),
65 GoToType(Vec<HoverGotoTypeData>), 68 GoToType(Vec<HoverGotoTypeData>),
66} 69}
67 70
@@ -148,6 +151,10 @@ pub(crate) fn hover(
148 res.actions.push(action); 151 res.actions.push(action);
149 } 152 }
150 153
154 if let Some(action) = show_fn_references_action(db, definition) {
155 res.actions.push(action);
156 }
157
151 if let Some(action) = runnable_action(&sema, definition, position.file_id) { 158 if let Some(action) = runnable_action(&sema, definition, position.file_id) {
152 res.actions.push(action); 159 res.actions.push(action);
153 } 160 }
@@ -211,6 +218,18 @@ fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<Hov
211 adt.try_to_nav(db).map(to_action) 218 adt.try_to_nav(db).map(to_action)
212} 219}
213 220
221fn show_fn_references_action(db: &RootDatabase, def: Definition) -> Option<HoverAction> {
222 match def {
223 Definition::ModuleDef(ModuleDef::Function(it)) => it.try_to_nav(db).map(|nav_target| {
224 HoverAction::Reference(FilePosition {
225 file_id: nav_target.file_id,
226 offset: nav_target.focus_or_full_range().start(),
227 })
228 }),
229 _ => None,
230 }
231}
232
214fn runnable_action( 233fn runnable_action(
215 sema: &Semantics<RootDatabase>, 234 sema: &Semantics<RootDatabase>,
216 def: Definition, 235 def: Definition,
@@ -2377,6 +2396,14 @@ fn foo_$0test() {}
2377"#, 2396"#,
2378 expect![[r#" 2397 expect![[r#"
2379 [ 2398 [
2399 Reference(
2400 FilePosition {
2401 file_id: FileId(
2402 0,
2403 ),
2404 offset: 11,
2405 },
2406 ),
2380 Runnable( 2407 Runnable(
2381 Runnable { 2408 Runnable {
2382 nav: NavigationTarget { 2409 nav: NavigationTarget {