aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/hover.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/hover.rs')
-rw-r--r--crates/ra_ide_api/src/hover.rs14
1 files changed, 8 insertions, 6 deletions
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 3206e68b9..bfa7cd67a 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -1,7 +1,7 @@
1use ra_db::SourceDatabase; 1use ra_db::SourceDatabase;
2use ra_syntax::{ 2use ra_syntax::{
3 AstNode, SyntaxNode, TreeArc, ast::{self, NameOwner, VisibilityOwner, TypeAscriptionOwner}, 3 AstNode, SyntaxNode, TreeArc, ast::{self, NameOwner, VisibilityOwner, TypeAscriptionOwner},
4 algo::{find_covering_node, find_node_at_offset, find_leaf_at_offset, visit::{visitor, Visitor}}, 4 algo::{find_covering_element, find_node_at_offset, find_token_at_offset, visit::{visitor, Visitor}},
5}; 5};
6use hir::HirDisplay; 6use hir::HirDisplay;
7 7
@@ -104,8 +104,11 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
104 } 104 }
105 105
106 if range.is_none() { 106 if range.is_none() {
107 let node = find_leaf_at_offset(file.syntax(), position.offset).find_map(|leaf| { 107 let node = find_token_at_offset(file.syntax(), position.offset).find_map(|token| {
108 leaf.ancestors().find(|n| ast::Expr::cast(*n).is_some() || ast::Pat::cast(*n).is_some()) 108 token
109 .parent()
110 .ancestors()
111 .find(|n| ast::Expr::cast(*n).is_some() || ast::Pat::cast(*n).is_some())
109 })?; 112 })?;
110 let frange = FileRange { file_id: position.file_id, range: node.range() }; 113 let frange = FileRange { file_id: position.file_id, range: node.range() };
111 res.extend(type_of(db, frange).map(rust_code_markup)); 114 res.extend(type_of(db, frange).map(rust_code_markup));
@@ -123,13 +126,12 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
123pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> { 126pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> {
124 let file = db.parse(frange.file_id); 127 let file = db.parse(frange.file_id);
125 let syntax = file.syntax(); 128 let syntax = file.syntax();
126 let leaf_node = find_covering_node(syntax, frange.range); 129 let leaf_node = find_covering_element(syntax, frange.range);
127 // if we picked identifier, expand to pattern/expression 130 // if we picked identifier, expand to pattern/expression
128 let node = leaf_node 131 let node = leaf_node
129 .ancestors() 132 .ancestors()
130 .take_while(|it| it.range() == leaf_node.range()) 133 .take_while(|it| it.range() == leaf_node.range())
131 .find(|&it| ast::Expr::cast(it).is_some() || ast::Pat::cast(it).is_some()) 134 .find(|&it| ast::Expr::cast(it).is_some() || ast::Pat::cast(it).is_some())?;
132 .unwrap_or(leaf_node);
133 let parent_fn = node.ancestors().find_map(ast::FnDef::cast)?; 135 let parent_fn = node.ancestors().find_map(ast::FnDef::cast)?;
134 let function = hir::source_binder::function_from_source(db, frange.file_id, parent_fn)?; 136 let function = hir::source_binder::function_from_source(db, frange.file_id, parent_fn)?;
135 let infer = function.infer(db); 137 let infer = function.infer(db);