diff options
Diffstat (limited to 'crates/ra_analysis/src/hover.rs')
-rw-r--r-- | crates/ra_analysis/src/hover.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/crates/ra_analysis/src/hover.rs b/crates/ra_analysis/src/hover.rs index c99d87da6..766fa0547 100644 --- a/crates/ra_analysis/src/hover.rs +++ b/crates/ra_analysis/src/hover.rs | |||
@@ -2,7 +2,7 @@ use ra_db::{Cancelable, SyntaxDatabase}; | |||
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | AstNode, SyntaxNode, | 3 | AstNode, SyntaxNode, |
4 | ast::{self, NameOwner}, | 4 | ast::{self, NameOwner}, |
5 | algo::visit::{visitor, Visitor}, | 5 | algo::{find_covering_node, visit::{visitor, Visitor}}, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget}; | 8 | use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget}; |
@@ -27,7 +27,7 @@ pub(crate) fn hover( | |||
27 | file_id: position.file_id, | 27 | file_id: position.file_id, |
28 | range: expr.syntax().range(), | 28 | range: expr.syntax().range(), |
29 | }; | 29 | }; |
30 | res.extend(db.type_of(frange)?); | 30 | res.extend(type_of(db, frange)?); |
31 | expr.syntax().range() | 31 | expr.syntax().range() |
32 | }; | 32 | }; |
33 | if res.is_empty() { | 33 | if res.is_empty() { |
@@ -37,6 +37,20 @@ pub(crate) fn hover( | |||
37 | Ok(Some(res)) | 37 | Ok(Some(res)) |
38 | } | 38 | } |
39 | 39 | ||
40 | pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Cancelable<Option<String>> { | ||
41 | let file = db.source_file(frange.file_id); | ||
42 | let syntax = file.syntax(); | ||
43 | let node = find_covering_node(syntax, frange.range); | ||
44 | let parent_fn = ctry!(node.ancestors().find_map(ast::FnDef::cast)); | ||
45 | let function = ctry!(hir::source_binder::function_from_source( | ||
46 | db, | ||
47 | frange.file_id, | ||
48 | parent_fn | ||
49 | )?); | ||
50 | let infer = function.infer(db)?; | ||
51 | Ok(infer.type_of_node(node).map(|t| t.to_string())) | ||
52 | } | ||
53 | |||
40 | // FIXME: this should not really use navigation target. Rather, approximatelly | 54 | // FIXME: this should not really use navigation target. Rather, approximatelly |
41 | // resovled symbol should return a `DefId`. | 55 | // resovled symbol should return a `DefId`. |
42 | fn doc_text_for(db: &RootDatabase, nav: NavigationTarget) -> Cancelable<Option<String>> { | 56 | fn doc_text_for(db: &RootDatabase, nav: NavigationTarget) -> Cancelable<Option<String>> { |