diff --git a/crates/ra_assists/src/assist_context.rs b/crates/ra_assists/src/assist_context.rs index ee614de726..3640bb4d26 100644 --- a/crates/ra_assists/src/assist_context.rs +++ b/crates/ra_assists/src/assist_context.rs @@ -55,7 +55,6 @@ use crate::{ pub(crate) struct AssistContext<'a> { pub(crate) config: &'a AssistConfig, pub(crate) sema: Semantics<'a, RootDatabase>, - pub(crate) db: &'a RootDatabase, pub(crate) frange: FileRange, source_file: SourceFile, } @@ -67,8 +66,11 @@ impl<'a> AssistContext<'a> { frange: FileRange, ) -> AssistContext<'a> { let source_file = sema.parse(frange.file_id); - let db = sema.db; - AssistContext { config, sema, db, frange, source_file } + AssistContext { config, sema, frange, source_file } + } + + pub(crate) fn db(&self) -> &RootDatabase { + self.sema.db } // NB, this ignores active selection. diff --git a/crates/ra_assists/src/handlers/add_explicit_type.rs b/crates/ra_assists/src/handlers/add_explicit_type.rs index 90b06a6259..11df922a23 100644 --- a/crates/ra_assists/src/handlers/add_explicit_type.rs +++ b/crates/ra_assists/src/handlers/add_explicit_type.rs @@ -57,7 +57,7 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Optio return None; } - let inferred_type = ty.display_source_code(ctx.db, module.into()).ok()?; + let inferred_type = ty.display_source_code(ctx.db(), module.into()).ok()?; acc.add( AssistId("add_explicit_type"), format!("Insert explicit type `{}`", inferred_type), diff --git a/crates/ra_assists/src/handlers/add_function.rs b/crates/ra_assists/src/handlers/add_function.rs index 1cfbd75aa1..fc4e823099 100644 --- a/crates/ra_assists/src/handlers/add_function.rs +++ b/crates/ra_assists/src/handlers/add_function.rs @@ -117,7 +117,7 @@ impl FunctionBuilder { let mut file = ctx.frange.file_id; let target = match &target_module { Some(target_module) => { - let module_source = target_module.definition_source(ctx.db); + let module_source = target_module.definition_source(ctx.db()); let (in_file, target) = next_space_for_fn_in_module(ctx.sema.db, &module_source)?; file = in_file; target @@ -269,7 +269,7 @@ fn fn_arg_type( return None; } - if let Ok(rendered) = ty.display_source_code(ctx.db, target_module.into()) { + if let Ok(rendered) = ty.display_source_code(ctx.db(), target_module.into()) { Some(rendered) } else { None diff --git a/crates/ra_assists/src/handlers/add_missing_impl_members.rs b/crates/ra_assists/src/handlers/add_missing_impl_members.rs index abacd4065f..77e092f623 100644 --- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs @@ -128,9 +128,9 @@ fn add_missing_impl_members_inner( let missing_items = get_missing_assoc_items(&ctx.sema, &impl_def) .iter() .map(|i| match i { - hir::AssocItem::Function(i) => ast::AssocItem::FnDef(i.source(ctx.db).value), - hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAliasDef(i.source(ctx.db).value), - hir::AssocItem::Const(i) => ast::AssocItem::ConstDef(i.source(ctx.db).value), + hir::AssocItem::Function(i) => ast::AssocItem::FnDef(i.source(ctx.db()).value), + hir::AssocItem::TypeAlias(i) => ast::AssocItem::TypeAliasDef(i.source(ctx.db()).value), + hir::AssocItem::Const(i) => ast::AssocItem::ConstDef(i.source(ctx.db()).value), }) .filter(|t| def_name(&t).is_some()) .filter(|t| match t { diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs index 837aa83774..e41b2aa06d 100644 --- a/crates/ra_assists/src/handlers/add_new.rs +++ b/crates/ra_assists/src/handlers/add_new.rs @@ -122,7 +122,7 @@ fn generate_impl_text(strukt: &ast::StructDef, code: &str) -> String { // FIXME: change the new fn checking to a more semantic approach when that's more // viable (e.g. we process proc macros, etc) fn find_struct_impl(ctx: &AssistContext, strukt: &ast::StructDef) -> Option> { - let db = ctx.db; + let db = ctx.db(); let module = strukt.syntax().ancestors().find(|node| { ast::Module::can_cast(node.kind()) || ast::SourceFile::can_cast(node.kind()) })?; diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs index d1cafa7d9d..e8060a4916 100644 --- a/crates/ra_assists/src/handlers/auto_import.rs +++ b/crates/ra_assists/src/handlers/auto_import.rs @@ -36,7 +36,7 @@ use crate::{utils::insert_use_statement, AssistContext, AssistId, Assists, Group // ``` pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let auto_import_assets = AutoImportAssets::new(&ctx)?; - let proposed_imports = auto_import_assets.search_for_imports(ctx.db); + let proposed_imports = auto_import_assets.search_for_imports(ctx.db()); if proposed_imports.is_empty() { return None; } diff --git a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs index 43b4584b45..bdf9d7ae26 100644 --- a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs @@ -37,15 +37,15 @@ pub(crate) fn extract_struct_from_enum_variant( }; let variant_name = variant.name()?.to_string(); let variant_hir = ctx.sema.to_def(&variant)?; - if existing_struct_def(ctx.db, &variant_name, &variant_hir) { + if existing_struct_def(ctx.db(), &variant_name, &variant_hir) { return None; } let enum_ast = variant.parent_enum(); let visibility = enum_ast.visibility(); let enum_hir = ctx.sema.to_def(&enum_ast)?; - let variant_hir_name = variant_hir.name(ctx.db); + let variant_hir_name = variant_hir.name(ctx.db()); let enum_module_def = ModuleDef::from(enum_hir); - let current_module = enum_hir.module(ctx.db); + let current_module = enum_hir.module(ctx.db()); let target = variant.syntax().text_range(); acc.add( AssistId("extract_struct_from_enum_variant"), @@ -53,7 +53,7 @@ pub(crate) fn extract_struct_from_enum_variant( target, |builder| { let definition = Definition::ModuleDef(ModuleDef::EnumVariant(variant_hir)); - let res = definition.find_usages(&ctx.db, None); + let res = definition.find_usages(&ctx.db(), None); let start_offset = variant.parent_enum().syntax().text_range().start(); let mut visited_modules_set = FxHashSet::default(); visited_modules_set.insert(current_module); @@ -101,7 +101,7 @@ fn insert_import( enum_module_def: &ModuleDef, variant_hir_name: &Name, ) -> Option<()> { - let db = ctx.db; + let db = ctx.db(); let mod_path = module.find_use_path(db, enum_module_def.clone()); if let Some(mut mod_path) = mod_path { mod_path.segments.pop(); diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs index 64270c86fa..5b12356823 100644 --- a/crates/ra_assists/src/handlers/fill_match_arms.rs +++ b/crates/ra_assists/src/handlers/fill_match_arms.rs @@ -51,11 +51,11 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option< let module = ctx.sema.scope(expr.syntax()).module()?; let missing_arms: Vec = if let Some(enum_def) = resolve_enum_def(&ctx.sema, &expr) { - let variants = enum_def.variants(ctx.db); + let variants = enum_def.variants(ctx.db()); let mut variants = variants .into_iter() - .filter_map(|variant| build_pat(ctx.db, module, variant)) + .filter_map(|variant| build_pat(ctx.db(), module, variant)) .filter(|variant_pat| is_variant_missing(&mut arms, variant_pat)) .map(|pat| make::match_arm(iter::once(pat), make::expr_empty_block())) .collect::>(); @@ -84,11 +84,11 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option< // where each tuple represents a proposed match arm. enum_defs .into_iter() - .map(|enum_def| enum_def.variants(ctx.db)) + .map(|enum_def| enum_def.variants(ctx.db())) .multi_cartesian_product() .map(|variants| { let patterns = - variants.into_iter().filter_map(|variant| build_pat(ctx.db, module, variant)); + variants.into_iter().filter_map(|variant| build_pat(ctx.db(), module, variant)); ast::Pat::from(make::tuple_pat(patterns)) }) .filter(|variant_pat| is_variant_missing(&mut arms, variant_pat)) diff --git a/crates/ra_assists/src/handlers/fix_visibility.rs b/crates/ra_assists/src/handlers/fix_visibility.rs index 19d4dac5e1..c0f57c3297 100644 --- a/crates/ra_assists/src/handlers/fix_visibility.rs +++ b/crates/ra_assists/src/handlers/fix_visibility.rs @@ -41,14 +41,14 @@ fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext) -> O }; let current_module = ctx.sema.scope(&path.syntax()).module()?; - let target_module = def.module(ctx.db)?; + let target_module = def.module(ctx.db())?; - let vis = target_module.visibility_of(ctx.db, &def)?; - if vis.is_visible_from(ctx.db, current_module.into()) { + let vis = target_module.visibility_of(ctx.db(), &def)?; + if vis.is_visible_from(ctx.db(), current_module.into()) { return None; }; - let (offset, target, target_file, target_name) = target_data_for_def(ctx.db, def)?; + let (offset, target, target_file, target_name) = target_data_for_def(ctx.db(), def)?; let missing_visibility = if current_module.krate() == target_module.krate() { "pub(crate)" } else { "pub" }; @@ -72,16 +72,16 @@ fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext) -> let (record_field_def, _) = ctx.sema.resolve_record_field(&record_field)?; let current_module = ctx.sema.scope(record_field.syntax()).module()?; - let visibility = record_field_def.visibility(ctx.db); - if visibility.is_visible_from(ctx.db, current_module.into()) { + let visibility = record_field_def.visibility(ctx.db()); + if visibility.is_visible_from(ctx.db(), current_module.into()) { return None; } - let parent = record_field_def.parent_def(ctx.db); - let parent_name = parent.name(ctx.db); - let target_module = parent.module(ctx.db); + let parent = record_field_def.parent_def(ctx.db()); + let parent_name = parent.name(ctx.db()); + let target_module = parent.module(ctx.db()); - let in_file_source = record_field_def.source(ctx.db); + let in_file_source = record_field_def.source(ctx.db()); let (offset, target) = match in_file_source.value { hir::FieldSource::Named(it) => { let s = it.syntax(); @@ -95,9 +95,9 @@ fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext) -> let missing_visibility = if current_module.krate() == target_module.krate() { "pub(crate)" } else { "pub" }; - let target_file = in_file_source.file_id.original_file(ctx.db); + let target_file = in_file_source.file_id.original_file(ctx.db()); - let target_name = record_field_def.name(ctx.db); + let target_name = record_field_def.name(ctx.db()); let assist_label = format!("Change visibility of {}.{} to {}", parent_name, target_name, missing_visibility); diff --git a/crates/ra_assists/src/handlers/inline_local_variable.rs b/crates/ra_assists/src/handlers/inline_local_variable.rs index d26e688479..f4fb0056bc 100644 --- a/crates/ra_assists/src/handlers/inline_local_variable.rs +++ b/crates/ra_assists/src/handlers/inline_local_variable.rs @@ -44,7 +44,7 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O let def = ctx.sema.to_def(&bind_pat)?; let def = Definition::Local(def); - let refs = def.find_usages(ctx.db, None); + let refs = def.find_usages(ctx.db(), None); if refs.is_empty() { mark::hit!(test_not_applicable_if_variable_unused); return None; diff --git a/crates/ra_assists/src/handlers/reorder_fields.rs b/crates/ra_assists/src/handlers/reorder_fields.rs index bc58ce5fe1..b8cf30e7f1 100644 --- a/crates/ra_assists/src/handlers/reorder_fields.rs +++ b/crates/ra_assists/src/handlers/reorder_fields.rs @@ -90,10 +90,10 @@ fn struct_definition(path: &ast::Path, sema: &Semantics) -> Option fn compute_fields_ranks(path: &ast::Path, ctx: &AssistContext) -> Option> { Some( struct_definition(path, &ctx.sema)? - .fields(ctx.db) + .fields(ctx.db()) .iter() .enumerate() - .map(|(idx, field)| (field.name(ctx.db).to_string(), idx)) + .map(|(idx, field)| (field.name(ctx.db()).to_string(), idx)) .collect(), ) }