From e3525527e35219e38e811b572406e14119853716 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Wed, 27 Feb 2019 09:49:22 +0200 Subject: Add support for hovering over the name of an item --- crates/ra_ide_api/src/goto_definition.rs | 2 +- crates/ra_ide_api/src/hover.rs | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide_api') 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( Approximate(navs) } -fn name_definition( +pub(crate) fn name_definition( db: &RootDatabase, file_id: FileId, 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(file.syntax(), position.offset) { + let navs = crate::goto_definition::name_definition(db, position.file_id, name); + + if let Some(navs) = navs { + for nav in navs { + res.extend(doc_text_for(db, nav)) + } + } + + if !res.is_empty() && range.is_none() { + range = Some(name.syntax().range()); + } } if range.is_none() { @@ -97,7 +109,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option(a: u32, b: u32) -> u32 {} + + fn main() { + } + "#, + &["pub fn foo(a: u32, b: u32) -> u32"], + ); + } + #[test] fn hover_some() { let (analysis, position) = single_file_with_position( -- cgit v1.2.3