aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorsucccubbus <[email protected]>2019-12-13 20:10:25 +0000
committersucccubbus <[email protected]>2019-12-13 20:10:25 +0000
commit6c133017a80c41db361d7870bf57db3e43c4074a (patch)
treea3558bce01cd8e8452a14522250256cc976bba55 /crates
parent6c42eb1930f179bca1867eebcbf82c7bc10dd4c5 (diff)
try both surrounding tokens for hover
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide/src/hover.rs16
1 files changed, 12 insertions, 4 deletions
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 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::{db::AstDatabase, Adt, HasSource, HirDisplay}; 3use hir::{db::AstDatabase, Adt, HasSource, HirDisplay, InFile};
4use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
5use ra_syntax::{ 5use ra_syntax::{
6 algo::find_covering_element, 6 algo::find_covering_element,
7 ast::{self, DocCommentsOwner}, 7 ast::{self, DocCommentsOwner},
8 match_ast, AstNode, 8 match_ast, AstNode, SyntaxToken,
9}; 9};
10 10
11use crate::{ 11use crate::{
@@ -156,9 +156,17 @@ fn hover_text_from_name_kind(
156 156
157pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeInfo<HoverResult>> { 157pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeInfo<HoverResult>> {
158 let file = db.parse_or_expand(position.file_id.into())?; 158 let file = db.parse_or_expand(position.file_id.into())?;
159 let token = file.token_at_offset(position.offset).find(|it| !it.kind().is_trivia())?; 159 file.token_at_offset(position.offset)
160 let token = descend_into_macros(db, position.file_id, token); 160 .filter(|token| !token.kind().is_trivia())
161 .map(|token| descend_into_macros(db, position.file_id, token))
162 .find_map(|token| hover_token(db, position, token))
163}
161 164
165fn hover_token(
166 db: &RootDatabase,
167 position: FilePosition,
168 token: InFile<SyntaxToken>,
169) -> Option<RangeInfo<HoverResult>> {
162 let mut res = HoverResult::new(); 170 let mut res = HoverResult::new();
163 171
164 let mut range = match_ast! { 172 let mut range = match_ast! {