From 49e746b010bbba408e9e4b1a40d89642e4cb84c6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 22 Dec 2018 11:01:03 +0300 Subject: completion uses hir scopes --- crates/ra_hir/src/function.rs | 2 +- crates/ra_hir/src/function/scope.rs | 2 +- crates/ra_hir/src/source_binder.rs | 12 +++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/function.rs b/crates/ra_hir/src/function.rs index 5187dc051..2925beb16 100644 --- a/crates/ra_hir/src/function.rs +++ b/crates/ra_hir/src/function.rs @@ -27,7 +27,7 @@ impl Function { Function { fn_id } } - pub fn scope(&self, db: &impl HirDatabase) -> Arc { + pub fn scopes(&self, db: &impl HirDatabase) -> Arc { db.fn_scopes(self.fn_id) } diff --git a/crates/ra_hir/src/function/scope.rs b/crates/ra_hir/src/function/scope.rs index 77be25f1a..a1a580979 100644 --- a/crates/ra_hir/src/function/scope.rs +++ b/crates/ra_hir/src/function/scope.rs @@ -33,7 +33,7 @@ pub struct ScopeData { } impl FnScopes { - pub fn new(fn_def: ast::FnDef) -> FnScopes { + pub(crate) fn new(fn_def: ast::FnDef) -> FnScopes { let mut scopes = FnScopes { self_param: fn_def .param_list() diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index ce2a0f2e8..a0165aef2 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -74,6 +74,16 @@ pub fn function_from_source( fn_def: ast::FnDef, ) -> Cancelable> { let module = ctry!(module_from_child_node(db, file_id, fn_def.syntax())?); + let res = function_from_module(db, &module, fn_def); + Ok(Some(res)) +} + +pub fn function_from_module( + db: &impl HirDatabase, + module: &Module, + fn_def: ast::FnDef, +) -> Function { + let file_id = module.source().file_id(); let file_items = db.file_items(file_id); let item_id = file_items.id_of(file_id, fn_def.syntax()); let source_item_id = SourceItemId { @@ -86,7 +96,7 @@ pub fn function_from_source( module_id: module.module_id, source_item_id, }; - Ok(Some(Function::new(def_loc.id(db)))) + Function::new(def_loc.id(db)) } pub fn function_from_child_node( -- cgit v1.2.3