From 8e3e5ab2c81f238ea4e731f55eac79b74d9d84c3 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 5 Jan 2019 22:37:59 +0100 Subject: 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. --- crates/ra_analysis/src/completion/complete_scope.rs | 9 +++------ crates/ra_analysis/src/goto_defenition.rs | 2 +- crates/ra_analysis/src/imp.rs | 4 ++-- 3 files changed, 6 insertions(+), 9 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 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) -> None => return Ok(()), }; if let Some(function) = &ctx.function { - let scopes = function.scopes(ctx.db); + let scopes = function.scopes(ctx.db)?; complete_fn(acc, &scopes, ctx.offset); } @@ -40,20 +40,17 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> Ok(()) } -fn complete_fn(acc: &mut Completions, scopes: &hir::FnScopes, offset: TextUnit) { +fn complete_fn(acc: &mut Completions, scopes: &hir::ScopesWithSyntaxMapping, offset: TextUnit) { let mut shadowed = FxHashSet::default(); scopes .scope_chain_for_offset(offset) - .flat_map(|scope| scopes.entries(scope).iter()) + .flat_map(|scope| scopes.scopes.entries(scope).iter()) .filter(|entry| shadowed.insert(entry.name())) .for_each(|entry| { CompletionItem::new(CompletionKind::Reference, entry.name().to_string()) .kind(CompletionItemKind::Binding) .add_to(acc) }); - if scopes.self_param.is_some() { - CompletionItem::new(CompletionKind::Reference, "self").add_to(acc); - } } #[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( if let Some(fn_descr) = hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())? { - let scope = fn_descr.scopes(db); + let scope = fn_descr.scopes(db)?; // First try to resolve the symbol locally if let Some(entry) = scope.resolve_local_name(name_ref) { 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 { .collect::>(); ret.extend( descr - .scopes(self) + .scopes(self)? .find_all_refs(binding) .into_iter() .map(|ref_desc| (position.file_id, ref_desc.range)), @@ -185,7 +185,7 @@ impl db::RootDatabase { position.file_id, name_ref.syntax(), )?); - let scope = descr.scopes(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