From 136aba1cf32646278c4034541ee415f656f8bb5e Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 5 Jan 2019 16:32:07 +0100 Subject: Add HIR Expr machinery --- crates/ra_analysis/src/db.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'crates/ra_analysis') diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 5422a400b..074a7a7f6 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -106,6 +106,8 @@ salsa::database_storage! { fn struct_data() for hir::db::StructDataQuery; fn enum_data() for hir::db::EnumDataQuery; fn impls_in_module() for hir::db::ImplsInModuleQuery; + fn body_hir() for hir::db::BodyHirQuery; + fn body_syntax_mapping() for hir::db::BodySyntaxMappingQuery; } } } -- cgit v1.2.3 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') 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 From 98957f4e6f66469310072dff5dfc3e521a7cd555 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 6 Jan 2019 01:00:34 +0100 Subject: Add fn signature query --- crates/ra_analysis/src/db.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'crates/ra_analysis') diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs index 074a7a7f6..1709be5cf 100644 --- a/crates/ra_analysis/src/db.rs +++ b/crates/ra_analysis/src/db.rs @@ -108,6 +108,7 @@ salsa::database_storage! { fn impls_in_module() for hir::db::ImplsInModuleQuery; fn body_hir() for hir::db::BodyHirQuery; fn body_syntax_mapping() for hir::db::BodySyntaxMappingQuery; + fn fn_signature() for hir::db::FnSignatureQuery; } } } -- cgit v1.2.3