try both surrounding tokens for hover

This commit is contained in:
succcubbus 2019-12-13 21:10:25 +01:00
parent 6c42eb1930
commit 6c133017a8

View file

@ -1,11 +1,11 @@
//! FIXME: write short doc here //! 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_db::SourceDatabase;
use ra_syntax::{ use ra_syntax::{
algo::find_covering_element, algo::find_covering_element,
ast::{self, DocCommentsOwner}, ast::{self, DocCommentsOwner},
match_ast, AstNode, match_ast, AstNode, SyntaxToken,
}; };
use crate::{ use crate::{
@ -156,9 +156,17 @@ fn hover_text_from_name_kind(
pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeInfo<HoverResult>> { pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeInfo<HoverResult>> {
let file = db.parse_or_expand(position.file_id.into())?; let file = db.parse_or_expand(position.file_id.into())?;
let token = file.token_at_offset(position.offset).find(|it| !it.kind().is_trivia())?; file.token_at_offset(position.offset)
let token = descend_into_macros(db, position.file_id, token); .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<SyntaxToken>,
) -> Option<RangeInfo<HoverResult>> {
let mut res = HoverResult::new(); let mut res = HoverResult::new();
let mut range = match_ast! { let mut range = match_ast! {