aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r--crates/ra_analysis/src/completion/complete_scope.rs44
-rw-r--r--crates/ra_analysis/src/imp.rs6
2 files changed, 26 insertions, 24 deletions
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) ->
10 if !ctx.is_trivial_path { 10 if !ctx.is_trivial_path {
11 return Ok(()); 11 return Ok(());
12 } 12 }
13 let module = match &ctx.module {
14 Some(it) => it,
15 None => return Ok(()),
16 };
13 if let Some(fn_def) = ctx.enclosing_fn { 17 if let Some(fn_def) = ctx.enclosing_fn {
14 let scopes = hir::FnScopes::new(fn_def); 18 let function = hir::source_binder::function_from_module(ctx.db, module, fn_def);
19 let scopes = function.scopes(ctx.db);
15 complete_fn(acc, &scopes, ctx.offset); 20 complete_fn(acc, &scopes, ctx.offset);
16 } 21 }
17 22
18 if let Some(module) = &ctx.module { 23 let module_scope = module.scope(ctx.db)?;
19 let module_scope = module.scope(ctx.db)?; 24 module_scope
20 module_scope 25 .entries()
21 .entries() 26 .filter(|(_name, res)| {
22 .filter(|(_name, res)| { 27 // Don't expose this item
23 // Don't expose this item 28 match res.import {
24 match res.import { 29 None => true,
25 None => true, 30 Some(import) => {
26 Some(import) => { 31 let range = import.range(ctx.db, module.source().file_id());
27 let range = import.range(ctx.db, module.source().file_id()); 32 !range.is_subrange(&ctx.leaf.range())
28 !range.is_subrange(&ctx.leaf.range())
29 }
30 } 33 }
31 }) 34 }
32 .for_each(|(name, res)| { 35 })
33 CompletionItem::new(CompletionKind::Reference, name.to_string()) 36 .for_each(|(name, res)| {
34 .from_resolution(ctx.db, res) 37 CompletionItem::new(CompletionKind::Reference, name.to_string())
35 .add_to(acc) 38 .from_resolution(ctx.db, res)
36 }); 39 .add_to(acc)
37 } 40 });
38
39 Ok(()) 41 Ok(())
40} 42}
41 43
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 {
235 position.file_id, 235 position.file_id,
236 name_ref.syntax(), 236 name_ref.syntax(),
237 )? { 237 )? {
238 let scope = fn_descr.scope(&*self.db); 238 let scope = fn_descr.scopes(&*self.db);
239 // First try to resolve the symbol locally 239 // First try to resolve the symbol locally
240 if let Some(entry) = scope.resolve_local_name(name_ref) { 240 if let Some(entry) = scope.resolve_local_name(name_ref) {
241 rr.add_resolution( 241 rr.add_resolution(
@@ -294,7 +294,7 @@ impl AnalysisImpl {
294 let mut ret = vec![(position.file_id, binding.syntax().range())]; 294 let mut ret = vec![(position.file_id, binding.syntax().range())];
295 ret.extend( 295 ret.extend(
296 descr 296 descr
297 .scope(&*self.db) 297 .scopes(&*self.db)
298 .find_all_refs(binding) 298 .find_all_refs(binding)
299 .into_iter() 299 .into_iter()
300 .map(|ref_desc| (position.file_id, ref_desc.range)), 300 .map(|ref_desc| (position.file_id, ref_desc.range)),
@@ -322,7 +322,7 @@ impl AnalysisImpl {
322 position.file_id, 322 position.file_id,
323 name_ref.syntax(), 323 name_ref.syntax(),
324 )?); 324 )?);
325 let scope = descr.scope(db); 325 let scope = descr.scopes(db);
326 let resolved = ctry!(scope.resolve_local_name(name_ref)); 326 let resolved = ctry!(scope.resolve_local_name(name_ref));
327 let resolved = resolved.ptr().resolve(source_file); 327 let resolved = resolved.ptr().resolve(source_file);
328 let binding = ctry!(find_node_at_offset::<ast::BindPat>( 328 let binding = ctry!(find_node_at_offset::<ast::BindPat>(