From 7348f7883fa2bd571fff036c82e98c102d05c362 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 23 Dec 2018 12:05:54 +0100 Subject: Add testing infrastructure for type inference - move dir_tests to test_utils for that. --- crates/ra_analysis/src/imp.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'crates/ra_analysis/src/imp.rs') diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index b01382808..4e0631679 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -5,7 +5,8 @@ use std::{ use ra_editor::{self, find_node_at_offset, FileSymbol, LineIndex, LocalEdit}; use ra_syntax::{ - ast::{self, ArgListOwner, Expr, NameOwner}, + ast::{self, ArgListOwner, Expr, NameOwner, FnDef}, + algo::find_covering_node, AstNode, SourceFileNode, SyntaxKind::*, SyntaxNodeRef, TextRange, TextUnit, @@ -510,6 +511,17 @@ impl AnalysisImpl { Ok(None) } + pub fn type_of(&self, file_id: FileId, range: TextRange) -> Cancelable> { + let file = self.db.source_file(file_id); + let syntax = file.syntax(); + let node = find_covering_node(syntax, range); + let parent_fn = node.ancestors().filter_map(FnDef::cast).next(); + let parent_fn = if let Some(p) = parent_fn { p } else { return Ok(None) }; + let function = ctry!(source_binder::function_from_source(&*self.db, file_id, parent_fn)?); + let infer = function.infer(&*self.db); + Ok(infer.type_of_node(node).map(|t| t.to_string())) + } + fn index_resolve(&self, name_ref: ast::NameRef) -> Cancelable> { let name = name_ref.text(); let mut query = Query::new(name.to_string()); -- cgit v1.2.3 From 515c3bc59bfc227cbbb82f80b53c5c125be4fc30 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 23 Dec 2018 12:15:46 +0100 Subject: Cleanup --- crates/ra_analysis/src/imp.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'crates/ra_analysis/src/imp.rs') diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 4e0631679..f2912d235 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -516,8 +516,14 @@ impl AnalysisImpl { let syntax = file.syntax(); let node = find_covering_node(syntax, range); let parent_fn = node.ancestors().filter_map(FnDef::cast).next(); - let parent_fn = if let Some(p) = parent_fn { p } else { return Ok(None) }; - let function = ctry!(source_binder::function_from_source(&*self.db, file_id, parent_fn)?); + let parent_fn = if let Some(p) = parent_fn { + p + } else { + return Ok(None); + }; + let function = ctry!(source_binder::function_from_source( + &*self.db, file_id, parent_fn + )?); let infer = function.infer(&*self.db); Ok(infer.type_of_node(node).map(|t| t.to_string())) } -- cgit v1.2.3 From ef67581104eb00a0c199f0b2a3b558da8a6f90a2 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 23 Dec 2018 17:13:11 +0100 Subject: Resolve paths to defs (functions currently) during type inference --- crates/ra_analysis/src/imp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_analysis/src/imp.rs') diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index f2912d235..40996bfd7 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -524,7 +524,7 @@ impl AnalysisImpl { let function = ctry!(source_binder::function_from_source( &*self.db, file_id, parent_fn )?); - let infer = function.infer(&*self.db); + let infer = function.infer(&*self.db)?; Ok(infer.type_of_node(node).map(|t| t.to_string())) } -- cgit v1.2.3