aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-01-05 21:37:59 +0000
committerFlorian Diebold <[email protected]>2019-01-05 23:29:36 +0000
commit8e3e5ab2c81f238ea4e731f55eac79b74d9d84c3 (patch)
treee0388878b4d94ae71fbf82d3e3163c49c8e69c16 /crates/ra_analysis/src
parent136aba1cf32646278c4034541ee415f656f8bb5e (diff)
Make FnScopes use hir::Expr
This was a bit complicated. I've added a wrapper type for now that does the LocalSyntaxPtr <-> ExprId translation; we might want to get rid of that or give it a nicer interface.
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/completion/complete_scope.rs9
-rw-r--r--crates/ra_analysis/src/goto_defenition.rs2
-rw-r--r--crates/ra_analysis/src/imp.rs4
3 files changed, 6 insertions, 9 deletions
diff --git a/crates/ra_analysis/src/completion/complete_scope.rs b/crates/ra_analysis/src/completion/complete_scope.rs
index 4dead3689..21d77aa97 100644
--- a/crates/ra_analysis/src/completion/complete_scope.rs
+++ b/crates/ra_analysis/src/completion/complete_scope.rs
@@ -15,7 +15,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) ->
15 None => return Ok(()), 15 None => return Ok(()),
16 }; 16 };
17 if let Some(function) = &ctx.function { 17 if let Some(function) = &ctx.function {
18 let scopes = function.scopes(ctx.db); 18 let scopes = function.scopes(ctx.db)?;
19 complete_fn(acc, &scopes, ctx.offset); 19 complete_fn(acc, &scopes, ctx.offset);
20 } 20 }
21 21
@@ -40,20 +40,17 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) ->
40 Ok(()) 40 Ok(())
41} 41}
42 42
43fn complete_fn(acc: &mut Completions, scopes: &hir::FnScopes, offset: TextUnit) { 43fn complete_fn(acc: &mut Completions, scopes: &hir::ScopesWithSyntaxMapping, offset: TextUnit) {
44 let mut shadowed = FxHashSet::default(); 44 let mut shadowed = FxHashSet::default();
45 scopes 45 scopes
46 .scope_chain_for_offset(offset) 46 .scope_chain_for_offset(offset)
47 .flat_map(|scope| scopes.entries(scope).iter()) 47 .flat_map(|scope| scopes.scopes.entries(scope).iter())
48 .filter(|entry| shadowed.insert(entry.name())) 48 .filter(|entry| shadowed.insert(entry.name()))
49 .for_each(|entry| { 49 .for_each(|entry| {
50 CompletionItem::new(CompletionKind::Reference, entry.name().to_string()) 50 CompletionItem::new(CompletionKind::Reference, entry.name().to_string())
51 .kind(CompletionItemKind::Binding) 51 .kind(CompletionItemKind::Binding)
52 .add_to(acc) 52 .add_to(acc)
53 }); 53 });
54 if scopes.self_param.is_some() {
55 CompletionItem::new(CompletionKind::Reference, "self").add_to(acc);
56 }
57} 54}
58 55
59#[cfg(test)] 56#[cfg(test)]
diff --git a/crates/ra_analysis/src/goto_defenition.rs b/crates/ra_analysis/src/goto_defenition.rs
index e37421f8d..68b6ac3ba 100644
--- a/crates/ra_analysis/src/goto_defenition.rs
+++ b/crates/ra_analysis/src/goto_defenition.rs
@@ -28,7 +28,7 @@ pub(crate) fn reference_defenition(
28 if let Some(fn_descr) = 28 if let Some(fn_descr) =
29 hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())? 29 hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())?
30 { 30 {
31 let scope = fn_descr.scopes(db); 31 let scope = fn_descr.scopes(db)?;
32 // First try to resolve the symbol locally 32 // First try to resolve the symbol locally
33 if let Some(entry) = scope.resolve_local_name(name_ref) { 33 if let Some(entry) = scope.resolve_local_name(name_ref) {
34 let nav = NavigationTarget { 34 let nav = NavigationTarget {
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 6ab3c5476..5988fb779 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -157,7 +157,7 @@ impl db::RootDatabase {
157 .collect::<Vec<_>>(); 157 .collect::<Vec<_>>();
158 ret.extend( 158 ret.extend(
159 descr 159 descr
160 .scopes(self) 160 .scopes(self)?
161 .find_all_refs(binding) 161 .find_all_refs(binding)
162 .into_iter() 162 .into_iter()
163 .map(|ref_desc| (position.file_id, ref_desc.range)), 163 .map(|ref_desc| (position.file_id, ref_desc.range)),
@@ -185,7 +185,7 @@ impl db::RootDatabase {
185 position.file_id, 185 position.file_id,
186 name_ref.syntax(), 186 name_ref.syntax(),
187 )?); 187 )?);
188 let scope = descr.scopes(db); 188 let scope = descr.scopes(db)?;
189 let resolved = ctry!(scope.resolve_local_name(name_ref)); 189 let resolved = ctry!(scope.resolve_local_name(name_ref));
190 let resolved = resolved.ptr().resolve(source_file); 190 let resolved = resolved.ptr().resolve(source_file);
191 let binding = ctry!(find_node_at_offset::<ast::BindPat>( 191 let binding = ctry!(find_node_at_offset::<ast::BindPat>(