aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_analysis/src/completion/complete_scope.rs44
-rw-r--r--crates/ra_analysis/src/imp.rs6
-rw-r--r--crates/ra_hir/src/function.rs2
-rw-r--r--crates/ra_hir/src/function/scope.rs2
-rw-r--r--crates/ra_hir/src/source_binder.rs12
5 files changed, 39 insertions, 27 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>(
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 {
27 Function { fn_id } 27 Function { fn_id }
28 } 28 }
29 29
30 pub fn scope(&self, db: &impl HirDatabase) -> Arc<FnScopes> { 30 pub fn scopes(&self, db: &impl HirDatabase) -> Arc<FnScopes> {
31 db.fn_scopes(self.fn_id) 31 db.fn_scopes(self.fn_id)
32 } 32 }
33 33
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 {
33} 33}
34 34
35impl FnScopes { 35impl FnScopes {
36 pub fn new(fn_def: ast::FnDef) -> FnScopes { 36 pub(crate) fn new(fn_def: ast::FnDef) -> FnScopes {
37 let mut scopes = FnScopes { 37 let mut scopes = FnScopes {
38 self_param: fn_def 38 self_param: fn_def
39 .param_list() 39 .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(
74 fn_def: ast::FnDef, 74 fn_def: ast::FnDef,
75) -> Cancelable<Option<Function>> { 75) -> Cancelable<Option<Function>> {
76 let module = ctry!(module_from_child_node(db, file_id, fn_def.syntax())?); 76 let module = ctry!(module_from_child_node(db, file_id, fn_def.syntax())?);
77 let res = function_from_module(db, &module, fn_def);
78 Ok(Some(res))
79}
80
81pub fn function_from_module(
82 db: &impl HirDatabase,
83 module: &Module,
84 fn_def: ast::FnDef,
85) -> Function {
86 let file_id = module.source().file_id();
77 let file_items = db.file_items(file_id); 87 let file_items = db.file_items(file_id);
78 let item_id = file_items.id_of(file_id, fn_def.syntax()); 88 let item_id = file_items.id_of(file_id, fn_def.syntax());
79 let source_item_id = SourceItemId { 89 let source_item_id = SourceItemId {
@@ -86,7 +96,7 @@ pub fn function_from_source(
86 module_id: module.module_id, 96 module_id: module.module_id,
87 source_item_id, 97 source_item_id,
88 }; 98 };
89 Ok(Some(Function::new(def_loc.id(db)))) 99 Function::new(def_loc.id(db))
90} 100}
91 101
92pub fn function_from_child_node( 102pub fn function_from_child_node(