aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-02-06 15:40:28 +0000
committerAleksey Kladov <[email protected]>2020-02-06 15:40:28 +0000
commita173e31890c1eb03d9d4c123986baae4154cd4fa (patch)
treea2b4de01cd6128b70f0fc0cf4156b6537304ae56 /crates/ra_assists
parentff0f0fc31e84deb7aebf8ab6ec510051d531c9f2 (diff)
Make assists use ImportsLocator directly
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/Cargo.toml1
-rw-r--r--crates/ra_assists/src/lib.rs18
2 files changed, 10 insertions, 9 deletions
diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml
index 9d3091b91..6973038d4 100644
--- a/crates/ra_assists/Cargo.toml
+++ b/crates/ra_assists/Cargo.toml
@@ -18,5 +18,6 @@ ra_text_edit = { path = "../ra_text_edit" }
18ra_fmt = { path = "../ra_fmt" } 18ra_fmt = { path = "../ra_fmt" }
19ra_prof = { path = "../ra_prof" } 19ra_prof = { path = "../ra_prof" }
20ra_db = { path = "../ra_db" } 20ra_db = { path = "../ra_db" }
21ra_ide_db = { path = "../ra_ide_db" }
21hir = { path = "../ra_hir", package = "ra_hir" } 22hir = { path = "../ra_hir", package = "ra_hir" }
22test_utils = { path = "../test_utils" } 23test_utils = { path = "../test_utils" }
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;
16use either::Either; 16use either::Either;
17use hir::{db::HirDatabase, ModuleDef}; 17use hir::{db::HirDatabase, ModuleDef};
18use ra_db::FileRange; 18use ra_db::FileRange;
19use ra_ide_db::{imports_locator::ImportsLocatorIde, RootDatabase};
19use ra_syntax::{TextRange, TextUnit}; 20use ra_syntax::{TextRange, TextUnit};
20use ra_text_edit::TextEdit; 21use ra_text_edit::TextEdit;
21 22
@@ -88,20 +89,19 @@ pub trait ImportsLocator {
88 fn find_imports(&mut self, name_to_import: &str) -> Vec<ModuleDef>; 89 fn find_imports(&mut self, name_to_import: &str) -> Vec<ModuleDef>;
89} 90}
90 91
92impl ImportsLocator for ImportsLocatorIde<'_> {
93 fn find_imports(&mut self, name_to_import: &str) -> Vec<ModuleDef> {
94 self.find_imports(name_to_import)
95 }
96}
97
91/// Return all the assists applicable at the given position 98/// Return all the assists applicable at the given position
92/// and additional assists that need the imports locator functionality to work. 99/// and additional assists that need the imports locator functionality to work.
93/// 100///
94/// Assists are returned in the "resolved" state, that is with edit fully 101/// Assists are returned in the "resolved" state, that is with edit fully
95/// computed. 102/// computed.
96pub fn assists_with_imports_locator<H, F>( 103pub fn assists_with_imports_locator(db: &RootDatabase, range: FileRange) -> Vec<ResolvedAssist> {
97 db: &H, 104 let mut imports_locator = ImportsLocatorIde::new(db);
98 range: FileRange,
99 mut imports_locator: F,
100) -> Vec<ResolvedAssist>
101where
102 H: HirDatabase + 'static,
103 F: ImportsLocator,
104{
105 AssistCtx::with_ctx(db, range, true, |ctx| { 105 AssistCtx::with_ctx(db, range, true, |ctx| {
106 let mut assists = assists::all() 106 let mut assists = assists::all()
107 .iter() 107 .iter()