aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
authorVille Penttinen <[email protected]>2019-02-27 07:49:22 +0000
committerVille Penttinen <[email protected]>2019-02-27 07:49:22 +0000
commite3525527e35219e38e811b572406e14119853716 (patch)
tree1b5d2058ff7250e3ba99d949e082510d493956a1 /crates/ra_ide_api
parent79114c67b10698d6b73b84bdd782d7407752d3ca (diff)
Add support for hovering over the name of an item
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs2
-rw-r--r--crates/ra_ide_api/src/hover.rs28
2 files changed, 28 insertions, 2 deletions
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 1833e57d5..da33739be 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -110,7 +110,7 @@ pub(crate) fn reference_definition(
110 Approximate(navs) 110 Approximate(navs)
111} 111}
112 112
113fn name_definition( 113pub(crate) fn name_definition(
114 db: &RootDatabase, 114 db: &RootDatabase,
115 file_id: FileId, 115 file_id: FileId,
116 name: &ast::Name, 116 name: &ast::Name,
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index bd3b1e396..ef3b5df29 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -88,6 +88,18 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
88 if !res.is_empty() { 88 if !res.is_empty() {
89 range = Some(name_ref.syntax().range()) 89 range = Some(name_ref.syntax().range())
90 } 90 }
91 } else if let Some(name) = find_node_at_offset::<ast::Name>(file.syntax(), position.offset) {
92 let navs = crate::goto_definition::name_definition(db, position.file_id, name);
93
94 if let Some(navs) = navs {
95 for nav in navs {
96 res.extend(doc_text_for(db, nav))
97 }
98 }
99
100 if !res.is_empty() && range.is_none() {
101 range = Some(name.syntax().range());
102 }
91 } 103 }
92 104
93 if range.is_none() { 105 if range.is_none() {
@@ -97,7 +109,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
97 let frange = FileRange { file_id: position.file_id, range: node.range() }; 109 let frange = FileRange { file_id: position.file_id, range: node.range() };
98 res.extend(type_of(db, frange).map(Into::into)); 110 res.extend(type_of(db, frange).map(Into::into));
99 range = Some(node.range()); 111 range = Some(node.range());
100 }; 112 }
101 113
102 let range = range?; 114 let range = range?;
103 if res.is_empty() { 115 if res.is_empty() {
@@ -295,6 +307,20 @@ mod tests {
295 } 307 }
296 308
297 #[test] 309 #[test]
310 fn hover_shows_fn_signature_on_fn_name() {
311 check_hover_result(
312 r#"
313 //- /main.rs
314 pub fn foo<|>(a: u32, b: u32) -> u32 {}
315
316 fn main() {
317 }
318 "#,
319 &["pub fn foo(a: u32, b: u32) -> u32"],
320 );
321 }
322
323 #[test]
298 fn hover_some() { 324 fn hover_some() {
299 let (analysis, position) = single_file_with_position( 325 let (analysis, position) = single_file_with_position(
300 " 326 "