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 --- .../ra_analysis/src/completion/complete_scope.rs | 44 +++++++++++----------- crates/ra_analysis/src/imp.rs | 6 +-- 2 files changed, 26 insertions(+), 24 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/completion/complete_scope.rs b/crates/ra_analysis/src/completion/complete_scope.rs index 82610d63f..a57670e3b 100644 --- a/crates/ra_analysis/src/completion/complete_scope.rs +++ b/crates/ra_analysis/src/completion/complete_scope.rs @@ -10,32 +10,34 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> if !ctx.is_trivial_path { return Ok(()); } + let module = match &ctx.module { + Some(it) => it, + None => return Ok(()), + }; if let Some(fn_def) = ctx.enclosing_fn { - let scopes = hir::FnScopes::new(fn_def); + let function = hir::source_binder::function_from_module(ctx.db, module, fn_def); + let scopes = function.scopes(ctx.db); complete_fn(acc, &scopes, ctx.offset); } - if let Some(module) = &ctx.module { - let module_scope = module.scope(ctx.db)?; - module_scope - .entries() - .filter(|(_name, res)| { - // Don't expose this item - match res.import { - None => true, - Some(import) => { - let range = import.range(ctx.db, module.source().file_id()); - !range.is_subrange(&ctx.leaf.range()) - } + let module_scope = module.scope(ctx.db)?; + module_scope + .entries() + .filter(|(_name, res)| { + // Don't expose this item + match res.import { + None => true, + Some(import) => { + let range = import.range(ctx.db, module.source().file_id()); + !range.is_subrange(&ctx.leaf.range()) } - }) - .for_each(|(name, res)| { - CompletionItem::new(CompletionKind::Reference, name.to_string()) - .from_resolution(ctx.db, res) - .add_to(acc) - }); - } - + } + }) + .for_each(|(name, res)| { + CompletionItem::new(CompletionKind::Reference, name.to_string()) + .from_resolution(ctx.db, res) + .add_to(acc) + }); Ok(()) } diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 340f7c78c..b01382808 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -235,7 +235,7 @@ impl AnalysisImpl { position.file_id, name_ref.syntax(), )? { - let scope = fn_descr.scope(&*self.db); + let scope = fn_descr.scopes(&*self.db); // First try to resolve the symbol locally if let Some(entry) = scope.resolve_local_name(name_ref) { rr.add_resolution( @@ -294,7 +294,7 @@ impl AnalysisImpl { let mut ret = vec![(position.file_id, binding.syntax().range())]; ret.extend( descr - .scope(&*self.db) + .scopes(&*self.db) .find_all_refs(binding) .into_iter() .map(|ref_desc| (position.file_id, ref_desc.range)), @@ -322,7 +322,7 @@ impl AnalysisImpl { position.file_id, name_ref.syntax(), )?); - let scope = descr.scope(db); + let scope = descr.scopes(db); let resolved = ctry!(scope.resolve_local_name(name_ref)); let resolved = resolved.ptr().resolve(source_file); let binding = ctry!(find_node_at_offset::( -- cgit v1.2.3