diff options
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r-- | crates/ra_analysis/src/hover.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/crates/ra_analysis/src/hover.rs b/crates/ra_analysis/src/hover.rs index 2cf79eebf..ba1fb9beb 100644 --- a/crates/ra_analysis/src/hover.rs +++ b/crates/ra_analysis/src/hover.rs | |||
@@ -3,7 +3,7 @@ use ra_editor::find_node_at_offset; | |||
3 | use ra_syntax::{ | 3 | use ra_syntax::{ |
4 | AstNode, SyntaxNode, | 4 | AstNode, SyntaxNode, |
5 | ast::{self, NameOwner}, | 5 | ast::{self, NameOwner}, |
6 | algo::{find_covering_node, visit::{visitor, Visitor}}, | 6 | algo::{find_covering_node, find_leaf_at_offset, visit::{visitor, Visitor}}, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget}; | 9 | use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget}; |
@@ -26,13 +26,17 @@ pub(crate) fn hover( | |||
26 | } | 26 | } |
27 | } | 27 | } |
28 | if range.is_none() { | 28 | if range.is_none() { |
29 | let expr: ast::Expr = ctry!(find_node_at_offset(file.syntax(), position.offset)); | 29 | let node = find_leaf_at_offset(file.syntax(), position.offset).find_map(|leaf| { |
30 | leaf.ancestors() | ||
31 | .find(|n| ast::Expr::cast(*n).is_some() || ast::Pat::cast(*n).is_some()) | ||
32 | }); | ||
33 | let node = ctry!(node); | ||
30 | let frange = FileRange { | 34 | let frange = FileRange { |
31 | file_id: position.file_id, | 35 | file_id: position.file_id, |
32 | range: expr.syntax().range(), | 36 | range: node.range(), |
33 | }; | 37 | }; |
34 | res.extend(type_of(db, frange)?); | 38 | res.extend(type_of(db, frange)?); |
35 | range = Some(expr.syntax().range()); | 39 | range = Some(node.range()); |
36 | }; | 40 | }; |
37 | 41 | ||
38 | let range = ctry!(range); | 42 | let range = ctry!(range); |
@@ -193,6 +197,13 @@ mod tests { | |||
193 | } | 197 | } |
194 | 198 | ||
195 | #[test] | 199 | #[test] |
200 | fn hover_for_local_variable_pat() { | ||
201 | let (analysis, position) = single_file_with_position("fn func(fo<|>o: i32) {}"); | ||
202 | let hover = analysis.hover(position).unwrap().unwrap(); | ||
203 | assert_eq!(hover.info, "i32"); | ||
204 | } | ||
205 | |||
206 | #[test] | ||
196 | fn test_type_of_for_function() { | 207 | fn test_type_of_for_function() { |
197 | let (analysis, range) = single_file_with_range( | 208 | let (analysis, range) = single_file_with_range( |
198 | " | 209 | " |