From a173e31890c1eb03d9d4c123986baae4154cd4fa Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 6 Feb 2020 16:40:28 +0100 Subject: Make assists use ImportsLocator directly --- crates/ra_assists/src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'crates/ra_assists/src/lib.rs') diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 625ebc4a2..0ebb8e8b0 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -16,6 +16,7 @@ pub mod ast_transform; use either::Either; use hir::{db::HirDatabase, ModuleDef}; use ra_db::FileRange; +use ra_ide_db::{imports_locator::ImportsLocatorIde, RootDatabase}; use ra_syntax::{TextRange, TextUnit}; use ra_text_edit::TextEdit; @@ -88,20 +89,19 @@ pub trait ImportsLocator { fn find_imports(&mut self, name_to_import: &str) -> Vec; } +impl ImportsLocator for ImportsLocatorIde<'_> { + fn find_imports(&mut self, name_to_import: &str) -> Vec { + self.find_imports(name_to_import) + } +} + /// Return all the assists applicable at the given position /// and additional assists that need the imports locator functionality to work. /// /// Assists are returned in the "resolved" state, that is with edit fully /// computed. -pub fn assists_with_imports_locator( - db: &H, - range: FileRange, - mut imports_locator: F, -) -> Vec -where - H: HirDatabase + 'static, - F: ImportsLocator, -{ +pub fn assists_with_imports_locator(db: &RootDatabase, range: FileRange) -> Vec { + let mut imports_locator = ImportsLocatorIde::new(db); AssistCtx::with_ctx(db, range, true, |ctx| { let mut assists = assists::all() .iter() -- cgit v1.2.3 From 2c922ef54958a82ce745e6db6834062f97f21bed Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 6 Feb 2020 16:53:42 +0100 Subject: Start switching assists to a root database --- crates/ra_assists/src/lib.rs | 61 ++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 33 deletions(-) (limited to 'crates/ra_assists/src/lib.rs') diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 0ebb8e8b0..a2109b751 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -14,7 +14,7 @@ mod test_db; pub mod ast_transform; use either::Either; -use hir::{db::HirDatabase, ModuleDef}; +use hir::ModuleDef; use ra_db::FileRange; use ra_ide_db::{imports_locator::ImportsLocatorIde, RootDatabase}; use ra_syntax::{TextRange, TextUnit}; @@ -62,10 +62,7 @@ impl ResolvedAssist { /// /// Assists are returned in the "unresolved" state, that is only labels are /// returned, without actual edits. -pub fn applicable_assists(db: &H, range: FileRange) -> Vec -where - H: HirDatabase + 'static, -{ +pub fn applicable_assists(db: &RootDatabase, range: FileRange) -> Vec { AssistCtx::with_ctx(db, range, false, |ctx| { assists::all() .iter() @@ -126,10 +123,7 @@ pub fn assists_with_imports_locator(db: &RootDatabase, range: FileRange) -> Vec< /// /// Assists are returned in the "resolved" state, that is with edit fully /// computed. -pub fn assists(db: &H, range: FileRange) -> Vec -where - H: HirDatabase + 'static, -{ +pub fn assists(db: &RootDatabase, range: FileRange) -> Vec { AssistCtx::with_ctx(db, range, true, |ctx| { let mut a = assists::all() .iter() @@ -231,17 +225,18 @@ mod helpers { use ra_syntax::TextRange; use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range}; - use crate::{test_db::TestDB, Assist, AssistCtx, ImportsLocator}; + use crate::{Assist, AssistCtx, ImportsLocator}; + use ra_ide_db::RootDatabase; use std::sync::Arc; // FIXME remove the `ModuleDefId` reexport from `ra_hir` when this gets removed. pub(crate) struct TestImportsLocator { - db: Arc, + db: Arc, test_file_id: FileId, } impl TestImportsLocator { - pub(crate) fn new(db: Arc, test_file_id: FileId) -> Self { + pub(crate) fn new(db: Arc, test_file_id: FileId) -> Self { TestImportsLocator { db, test_file_id } } } @@ -282,12 +277,12 @@ mod helpers { } pub(crate) fn check_assist( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, before: &str, after: &str, ) { let (before_cursor_pos, before) = extract_offset(before); - let (db, file_id) = TestDB::with_single_file(&before); + let (db, file_id) = RootDatabase::with_single_file(&before); let frange = FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; let assist = @@ -310,13 +305,13 @@ mod helpers { } pub(crate) fn check_assist_with_imports_locator( - assist: fn(AssistCtx, &mut F) -> Option, - imports_locator_provider: fn(db: Arc, file_id: FileId) -> F, + assist: fn(AssistCtx, &mut F) -> Option, + imports_locator_provider: fn(db: Arc, file_id: FileId) -> F, before: &str, after: &str, ) { let (before_cursor_pos, before) = extract_offset(before); - let (db, file_id) = TestDB::with_single_file(&before); + let (db, file_id) = RootDatabase::with_single_file(&before); let db = Arc::new(db); let mut imports_locator = imports_locator_provider(Arc::clone(&db), file_id); let frange = @@ -342,12 +337,12 @@ mod helpers { } pub(crate) fn check_assist_range( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, before: &str, after: &str, ) { let (range, before) = extract_range(before); - let (db, file_id) = TestDB::with_single_file(&before); + let (db, file_id) = RootDatabase::with_single_file(&before); let frange = FileRange { file_id, range }; let assist = AssistCtx::with_ctx(&db, frange, true, assist).expect("code action is not applicable"); @@ -364,12 +359,12 @@ mod helpers { } pub(crate) fn check_assist_target( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, before: &str, target: &str, ) { let (before_cursor_pos, before) = extract_offset(before); - let (db, file_id) = TestDB::with_single_file(&before); + let (db, file_id) = RootDatabase::with_single_file(&before); let frange = FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; let assist = @@ -384,12 +379,12 @@ mod helpers { } pub(crate) fn check_assist_range_target( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, before: &str, target: &str, ) { let (range, before) = extract_range(before); - let (db, file_id) = TestDB::with_single_file(&before); + let (db, file_id) = RootDatabase::with_single_file(&before); let frange = FileRange { file_id, range }; let assist = AssistCtx::with_ctx(&db, frange, true, assist).expect("code action is not applicable"); @@ -403,11 +398,11 @@ mod helpers { } pub(crate) fn check_assist_not_applicable( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, before: &str, ) { let (before_cursor_pos, before) = extract_offset(before); - let (db, file_id) = TestDB::with_single_file(&before); + let (db, file_id) = RootDatabase::with_single_file(&before); let frange = FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; let assist = AssistCtx::with_ctx(&db, frange, true, assist); @@ -415,12 +410,12 @@ mod helpers { } pub(crate) fn check_assist_with_imports_locator_not_applicable( - assist: fn(AssistCtx, &mut F) -> Option, - imports_locator_provider: fn(db: Arc, file_id: FileId) -> F, + assist: fn(AssistCtx, &mut F) -> Option, + imports_locator_provider: fn(db: Arc, file_id: FileId) -> F, before: &str, ) { let (before_cursor_pos, before) = extract_offset(before); - let (db, file_id) = TestDB::with_single_file(&before); + let (db, file_id) = RootDatabase::with_single_file(&before); let db = Arc::new(db); let mut imports_locator = imports_locator_provider(Arc::clone(&db), file_id); let frange = @@ -431,11 +426,11 @@ mod helpers { } pub(crate) fn check_assist_range_not_applicable( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, before: &str, ) { let (range, before) = extract_range(before); - let (db, file_id) = TestDB::with_single_file(&before); + let (db, file_id) = RootDatabase::with_single_file(&before); let frange = FileRange { file_id, range }; let assist = AssistCtx::with_ctx(&db, frange, true, assist); assert!(assist.is_none()); @@ -448,13 +443,13 @@ mod tests { use ra_syntax::TextRange; use test_utils::{extract_offset, extract_range}; - use crate::test_db::TestDB; + use ra_ide_db::RootDatabase; #[test] fn assist_order_field_struct() { let before = "struct Foo { <|>bar: u32 }"; let (before_cursor_pos, before) = extract_offset(before); - let (db, file_id) = TestDB::with_single_file(&before); + let (db, file_id) = RootDatabase::with_single_file(&before); let frange = FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; let assists = super::assists(&db, frange); @@ -478,7 +473,7 @@ mod tests { } }"; let (range, before) = extract_range(before); - let (db, file_id) = TestDB::with_single_file(&before); + let (db, file_id) = RootDatabase::with_single_file(&before); let frange = FileRange { file_id, range }; let assists = super::assists(&db, frange); let mut assists = assists.iter(); -- cgit v1.2.3 From f8965ffafd5cf467b3f0482ca962ba2bfd090161 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 6 Feb 2020 16:54:22 +0100 Subject: Remove assists TestDB --- crates/ra_assists/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) (limited to 'crates/ra_assists/src/lib.rs') diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index a2109b751..be6e06842 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -9,8 +9,6 @@ mod assist_ctx; mod marks; #[cfg(test)] mod doc_tests; -#[cfg(test)] -mod test_db; pub mod ast_transform; use either::Either; -- cgit v1.2.3 From cf812c12d1ac7944d1c18877ee93bea02d91e99f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 6 Feb 2020 16:58:57 +0100 Subject: Assists are not generic --- crates/ra_assists/src/lib.rs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'crates/ra_assists/src/lib.rs') diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index be6e06842..ad8438b6c 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -148,7 +148,6 @@ fn sort_assists(assists: &mut Vec) { mod assists { use crate::{Assist, AssistCtx, ImportsLocator}; - use hir::db::HirDatabase; mod add_derive; mod add_explicit_type; @@ -176,7 +175,7 @@ mod assists { mod move_bounds; mod early_return; - pub(crate) fn all() -> &'static [fn(AssistCtx) -> Option] { + pub(crate) fn all() -> &'static [fn(AssistCtx) -> Option] { &[ add_derive::add_derive, add_explicit_type::add_explicit_type, @@ -210,8 +209,8 @@ mod assists { ] } - pub(crate) fn all_with_imports_locator<'a, DB: HirDatabase, F: ImportsLocator>( - ) -> &'a [fn(AssistCtx, &mut F) -> Option] { + pub(crate) fn all_with_imports_locator<'a, F: ImportsLocator>( + ) -> &'a [fn(AssistCtx, &mut F) -> Option] { &[auto_import::auto_import] } } @@ -274,11 +273,7 @@ mod helpers { } } - pub(crate) fn check_assist( - assist: fn(AssistCtx) -> Option, - before: &str, - after: &str, - ) { + pub(crate) fn check_assist(assist: fn(AssistCtx) -> Option, before: &str, after: &str) { let (before_cursor_pos, before) = extract_offset(before); let (db, file_id) = RootDatabase::with_single_file(&before); let frange = @@ -303,7 +298,7 @@ mod helpers { } pub(crate) fn check_assist_with_imports_locator( - assist: fn(AssistCtx, &mut F) -> Option, + assist: fn(AssistCtx, &mut F) -> Option, imports_locator_provider: fn(db: Arc, file_id: FileId) -> F, before: &str, after: &str, @@ -335,7 +330,7 @@ mod helpers { } pub(crate) fn check_assist_range( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, before: &str, after: &str, ) { @@ -357,7 +352,7 @@ mod helpers { } pub(crate) fn check_assist_target( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, before: &str, target: &str, ) { @@ -377,7 +372,7 @@ mod helpers { } pub(crate) fn check_assist_range_target( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, before: &str, target: &str, ) { @@ -396,7 +391,7 @@ mod helpers { } pub(crate) fn check_assist_not_applicable( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, before: &str, ) { let (before_cursor_pos, before) = extract_offset(before); @@ -408,7 +403,7 @@ mod helpers { } pub(crate) fn check_assist_with_imports_locator_not_applicable( - assist: fn(AssistCtx, &mut F) -> Option, + assist: fn(AssistCtx, &mut F) -> Option, imports_locator_provider: fn(db: Arc, file_id: FileId) -> F, before: &str, ) { @@ -424,7 +419,7 @@ mod helpers { } pub(crate) fn check_assist_range_not_applicable( - assist: fn(AssistCtx) -> Option, + assist: fn(AssistCtx) -> Option, before: &str, ) { let (range, before) = extract_range(before); -- cgit v1.2.3 From ad204f7562747150c4f570d7ce648f2539530b76 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 6 Feb 2020 17:17:51 +0100 Subject: Mostly remove ImoportLocator infra --- crates/ra_assists/src/lib.rs | 158 ++----------------------------------------- 1 file changed, 6 insertions(+), 152 deletions(-) (limited to 'crates/ra_assists/src/lib.rs') diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index ad8438b6c..8285e93a4 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -12,9 +12,8 @@ mod doc_tests; pub mod ast_transform; use either::Either; -use hir::ModuleDef; use ra_db::FileRange; -use ra_ide_db::{imports_locator::ImportsLocatorIde, RootDatabase}; +use ra_ide_db::RootDatabase; use ra_syntax::{TextRange, TextUnit}; use ra_text_edit::TextEdit; @@ -73,50 +72,6 @@ pub fn applicable_assists(db: &RootDatabase, range: FileRange) -> Vec Vec; -} - -impl ImportsLocator for ImportsLocatorIde<'_> { - fn find_imports(&mut self, name_to_import: &str) -> Vec { - self.find_imports(name_to_import) - } -} - -/// Return all the assists applicable at the given position -/// and additional assists that need the imports locator functionality to work. -/// -/// Assists are returned in the "resolved" state, that is with edit fully -/// computed. -pub fn assists_with_imports_locator(db: &RootDatabase, range: FileRange) -> Vec { - let mut imports_locator = ImportsLocatorIde::new(db); - AssistCtx::with_ctx(db, range, true, |ctx| { - let mut assists = assists::all() - .iter() - .map(|f| f(ctx.clone())) - .chain( - assists::all_with_imports_locator() - .iter() - .map(|f| f(ctx.clone(), &mut imports_locator)), - ) - .filter_map(std::convert::identity) - .map(|a| match a { - Assist::Resolved { assist } => assist, - Assist::Unresolved { .. } => unreachable!(), - }) - .collect(); - sort_assists(&mut assists); - assists - }) -} - /// Return all the assists applicable at the given position. /// /// Assists are returned in the "resolved" state, that is with edit fully @@ -147,7 +102,7 @@ fn sort_assists(assists: &mut Vec) { } mod assists { - use crate::{Assist, AssistCtx, ImportsLocator}; + use crate::{Assist, AssistCtx}; mod add_derive; mod add_explicit_type; @@ -206,72 +161,19 @@ mod assists { raw_string::make_usual_string, raw_string::remove_hash, early_return::convert_to_guarded_return, + auto_import::auto_import, ] } - - pub(crate) fn all_with_imports_locator<'a, F: ImportsLocator>( - ) -> &'a [fn(AssistCtx, &mut F) -> Option] { - &[auto_import::auto_import] - } } #[cfg(test)] mod helpers { - use hir::db::DefDatabase; - use ra_db::{fixture::WithFixture, FileId, FileRange}; + use ra_db::{fixture::WithFixture, FileRange}; + use ra_ide_db::RootDatabase; use ra_syntax::TextRange; use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range}; - use crate::{Assist, AssistCtx, ImportsLocator}; - use ra_ide_db::RootDatabase; - use std::sync::Arc; - - // FIXME remove the `ModuleDefId` reexport from `ra_hir` when this gets removed. - pub(crate) struct TestImportsLocator { - db: Arc, - test_file_id: FileId, - } - - impl TestImportsLocator { - pub(crate) fn new(db: Arc, test_file_id: FileId) -> Self { - TestImportsLocator { db, test_file_id } - } - } - - impl ImportsLocator for TestImportsLocator { - fn find_imports(&mut self, name_to_import: &str) -> Vec { - let crate_def_map = self.db.crate_def_map(self.db.test_crate()); - let mut findings = Vec::new(); - - let mut module_ids_to_process = - crate_def_map.modules_for_file(self.test_file_id).collect::>(); - - while !module_ids_to_process.is_empty() { - let mut more_ids_to_process = Vec::new(); - for local_module_id in module_ids_to_process.drain(..) { - for (name, namespace_data) in - crate_def_map[local_module_id].scope.entries_without_primitives() - { - let found_a_match = &name.to_string() == name_to_import; - vec![namespace_data.types, namespace_data.values] - .into_iter() - .filter_map(std::convert::identity) - .for_each(|(module_def_id, _)| { - if found_a_match { - findings.push(module_def_id.into()); - } - if let hir::ModuleDefId::ModuleId(module_id) = module_def_id { - more_ids_to_process.push(module_id.local_id); - } - }); - } - } - module_ids_to_process = more_ids_to_process; - } - - findings - } - } + use crate::{Assist, AssistCtx}; pub(crate) fn check_assist(assist: fn(AssistCtx) -> Option, before: &str, after: &str) { let (before_cursor_pos, before) = extract_offset(before); @@ -297,38 +199,6 @@ mod helpers { assert_eq_text!(after, &actual); } - pub(crate) fn check_assist_with_imports_locator( - assist: fn(AssistCtx, &mut F) -> Option, - imports_locator_provider: fn(db: Arc, file_id: FileId) -> F, - before: &str, - after: &str, - ) { - let (before_cursor_pos, before) = extract_offset(before); - let (db, file_id) = RootDatabase::with_single_file(&before); - let db = Arc::new(db); - let mut imports_locator = imports_locator_provider(Arc::clone(&db), file_id); - let frange = - FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; - let assist = - AssistCtx::with_ctx(db.as_ref(), frange, true, |ctx| assist(ctx, &mut imports_locator)) - .expect("code action is not applicable"); - let action = match assist { - Assist::Unresolved { .. } => unreachable!(), - Assist::Resolved { assist } => assist.get_first_action(), - }; - - let actual = action.edit.apply(&before); - let actual_cursor_pos = match action.cursor_position { - None => action - .edit - .apply_to_offset(before_cursor_pos) - .expect("cursor position is affected by the edit"), - Some(off) => off, - }; - let actual = add_cursor(&actual, actual_cursor_pos); - assert_eq_text!(after, &actual); - } - pub(crate) fn check_assist_range( assist: fn(AssistCtx) -> Option, before: &str, @@ -402,22 +272,6 @@ mod helpers { assert!(assist.is_none()); } - pub(crate) fn check_assist_with_imports_locator_not_applicable( - assist: fn(AssistCtx, &mut F) -> Option, - imports_locator_provider: fn(db: Arc, file_id: FileId) -> F, - before: &str, - ) { - let (before_cursor_pos, before) = extract_offset(before); - let (db, file_id) = RootDatabase::with_single_file(&before); - let db = Arc::new(db); - let mut imports_locator = imports_locator_provider(Arc::clone(&db), file_id); - let frange = - FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; - let assist = - AssistCtx::with_ctx(db.as_ref(), frange, true, |ctx| assist(ctx, &mut imports_locator)); - assert!(assist.is_none()); - } - pub(crate) fn check_assist_range_not_applicable( assist: fn(AssistCtx) -> Option, before: &str, -- cgit v1.2.3 From d1e8b8d134da802eecef5cbcd5486bd542ad75b5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 6 Feb 2020 17:42:17 +0100 Subject: Fix tests --- crates/ra_assists/src/lib.rs | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'crates/ra_assists/src/lib.rs') diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 8285e93a4..1343043dd 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -168,16 +168,27 @@ mod assists { #[cfg(test)] mod helpers { - use ra_db::{fixture::WithFixture, FileRange}; - use ra_ide_db::RootDatabase; + use std::sync::Arc; + + use ra_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}; + use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase}; use ra_syntax::TextRange; use test_utils::{add_cursor, assert_eq_text, extract_offset, extract_range}; use crate::{Assist, AssistCtx}; + pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { + let (mut db, file_id) = RootDatabase::with_single_file(text); + // FIXME: ideally, this should be done by the above `RootDatabase::with_single_file`, + // but it looks like this might need specialization? :( + let local_roots = vec![db.file_source_root(file_id)]; + db.set_local_roots(Arc::new(local_roots)); + (db, file_id) + } + pub(crate) fn check_assist(assist: fn(AssistCtx) -> Option, before: &str, after: &str) { let (before_cursor_pos, before) = extract_offset(before); - let (db, file_id) = RootDatabase::with_single_file(&before); + let (db, file_id) = with_single_file(&before); let frange = FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; let assist = @@ -205,7 +216,7 @@ mod helpers { after: &str, ) { let (range, before) = extract_range(before); - let (db, file_id) = RootDatabase::with_single_file(&before); + let (db, file_id) = with_single_file(&before); let frange = FileRange { file_id, range }; let assist = AssistCtx::with_ctx(&db, frange, true, assist).expect("code action is not applicable"); @@ -227,7 +238,7 @@ mod helpers { target: &str, ) { let (before_cursor_pos, before) = extract_offset(before); - let (db, file_id) = RootDatabase::with_single_file(&before); + let (db, file_id) = with_single_file(&before); let frange = FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; let assist = @@ -247,7 +258,7 @@ mod helpers { target: &str, ) { let (range, before) = extract_range(before); - let (db, file_id) = RootDatabase::with_single_file(&before); + let (db, file_id) = with_single_file(&before); let frange = FileRange { file_id, range }; let assist = AssistCtx::with_ctx(&db, frange, true, assist).expect("code action is not applicable"); @@ -265,7 +276,7 @@ mod helpers { before: &str, ) { let (before_cursor_pos, before) = extract_offset(before); - let (db, file_id) = RootDatabase::with_single_file(&before); + let (db, file_id) = with_single_file(&before); let frange = FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; let assist = AssistCtx::with_ctx(&db, frange, true, assist); @@ -277,7 +288,7 @@ mod helpers { before: &str, ) { let (range, before) = extract_range(before); - let (db, file_id) = RootDatabase::with_single_file(&before); + let (db, file_id) = with_single_file(&before); let frange = FileRange { file_id, range }; let assist = AssistCtx::with_ctx(&db, frange, true, assist); assert!(assist.is_none()); @@ -286,17 +297,17 @@ mod helpers { #[cfg(test)] mod tests { - use ra_db::{fixture::WithFixture, FileRange}; + use ra_db::FileRange; use ra_syntax::TextRange; use test_utils::{extract_offset, extract_range}; - use ra_ide_db::RootDatabase; + use crate::helpers; #[test] fn assist_order_field_struct() { let before = "struct Foo { <|>bar: u32 }"; let (before_cursor_pos, before) = extract_offset(before); - let (db, file_id) = RootDatabase::with_single_file(&before); + let (db, file_id) = helpers::with_single_file(&before); let frange = FileRange { file_id, range: TextRange::offset_len(before_cursor_pos, 0.into()) }; let assists = super::assists(&db, frange); @@ -320,7 +331,7 @@ mod tests { } }"; let (range, before) = extract_range(before); - let (db, file_id) = RootDatabase::with_single_file(&before); + let (db, file_id) = helpers::with_single_file(&before); let frange = FileRange { file_id, range }; let assists = super::assists(&db, frange); let mut assists = assists.iter(); -- cgit v1.2.3