diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_analysis/src/hover.rs | 18 | ||||
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 16 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 2 |
3 files changed, 18 insertions, 18 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>> { |
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 1e9129c4f..e2871451c 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -8,8 +8,7 @@ use hir::{ | |||
8 | use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase}; | 8 | use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase}; |
9 | use ra_editor::{self, find_node_at_offset, assists, LocalEdit, Severity}; | 9 | use ra_editor::{self, find_node_at_offset, assists, LocalEdit, Severity}; |
10 | use ra_syntax::{ | 10 | use ra_syntax::{ |
11 | algo::find_covering_node, | 11 | ast::{self, ArgListOwner, Expr, NameOwner}, |
12 | ast::{self, ArgListOwner, Expr, FnDef, NameOwner}, | ||
13 | AstNode, SourceFileNode, | 12 | AstNode, SourceFileNode, |
14 | SyntaxKind::*, | 13 | SyntaxKind::*, |
15 | SyntaxNodeRef, TextRange, TextUnit, | 14 | SyntaxNodeRef, TextRange, TextUnit, |
@@ -398,19 +397,6 @@ impl db::RootDatabase { | |||
398 | Ok(None) | 397 | Ok(None) |
399 | } | 398 | } |
400 | 399 | ||
401 | pub(crate) fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { | ||
402 | let file = self.source_file(frange.file_id); | ||
403 | let syntax = file.syntax(); | ||
404 | let node = find_covering_node(syntax, frange.range); | ||
405 | let parent_fn = ctry!(node.ancestors().find_map(FnDef::cast)); | ||
406 | let function = ctry!(source_binder::function_from_source( | ||
407 | self, | ||
408 | frange.file_id, | ||
409 | parent_fn | ||
410 | )?); | ||
411 | let infer = function.infer(self)?; | ||
412 | Ok(infer.type_of_node(node).map(|t| t.to_string())) | ||
413 | } | ||
414 | pub(crate) fn rename( | 400 | pub(crate) fn rename( |
415 | &self, | 401 | &self, |
416 | position: FilePosition, | 402 | position: FilePosition, |
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 0e32a15f8..b068119d2 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -450,7 +450,7 @@ impl Analysis { | |||
450 | } | 450 | } |
451 | /// Computes the type of the expression at the given position. | 451 | /// Computes the type of the expression at the given position. |
452 | pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { | 452 | pub fn type_of(&self, frange: FileRange) -> Cancelable<Option<String>> { |
453 | self.db.type_of(frange) | 453 | hover::type_of(&*self.db, frange) |
454 | } | 454 | } |
455 | /// Returns the edit required to rename reference at the position to the new | 455 | /// Returns the edit required to rename reference at the position to the new |
456 | /// name. | 456 | /// name. |