From 6c133017a80c41db361d7870bf57db3e43c4074a Mon Sep 17 00:00:00 2001 From: succcubbus <16743652+succcubbus@users.noreply.github.com> Date: Fri, 13 Dec 2019 21:10:25 +0100 Subject: try both surrounding tokens for hover --- crates/ra_ide/src/hover.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index b2909bf38..5b48b1998 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -1,11 +1,11 @@ //! FIXME: write short doc here -use hir::{db::AstDatabase, Adt, HasSource, HirDisplay}; +use hir::{db::AstDatabase, Adt, HasSource, HirDisplay, InFile}; use ra_db::SourceDatabase; use ra_syntax::{ algo::find_covering_element, ast::{self, DocCommentsOwner}, - match_ast, AstNode, + match_ast, AstNode, SyntaxToken, }; use crate::{ @@ -156,9 +156,17 @@ fn hover_text_from_name_kind( pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option> { let file = db.parse_or_expand(position.file_id.into())?; - let token = file.token_at_offset(position.offset).find(|it| !it.kind().is_trivia())?; - let token = descend_into_macros(db, position.file_id, token); + file.token_at_offset(position.offset) + .filter(|token| !token.kind().is_trivia()) + .map(|token| descend_into_macros(db, position.file_id, token)) + .find_map(|token| hover_token(db, position, token)) +} +fn hover_token( + db: &RootDatabase, + position: FilePosition, + token: InFile, +) -> Option> { let mut res = HoverResult::new(); let mut range = match_ast! { -- cgit v1.2.3