diff options
author | Aleksey Kladov <[email protected]> | 2020-02-06 16:17:51 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-06 16:17:51 +0000 |
commit | ad204f7562747150c4f570d7ce648f2539530b76 (patch) | |
tree | cfb4d43e5dac678eedf2537c9981111a2364f30c /crates/ra_assists/src/assists | |
parent | cf812c12d1ac7944d1c18877ee93bea02d91e99f (diff) |
Mostly remove ImoportLocator infra
Diffstat (limited to 'crates/ra_assists/src/assists')
-rw-r--r-- | crates/ra_assists/src/assists/auto_import.rs | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/crates/ra_assists/src/assists/auto_import.rs b/crates/ra_assists/src/assists/auto_import.rs index 48ab336b1..219051063 100644 --- a/crates/ra_assists/src/assists/auto_import.rs +++ b/crates/ra_assists/src/assists/auto_import.rs | |||
@@ -6,8 +6,9 @@ use ra_syntax::{ | |||
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | assist_ctx::{ActionBuilder, Assist, AssistCtx}, | 8 | assist_ctx::{ActionBuilder, Assist, AssistCtx}, |
9 | auto_import_text_edit, AssistId, ImportsLocator, | 9 | auto_import_text_edit, AssistId, |
10 | }; | 10 | }; |
11 | use ra_ide_db::imports_locator::ImportsLocatorIde; | ||
11 | 12 | ||
12 | // Assist: auto_import | 13 | // Assist: auto_import |
13 | // | 14 | // |
@@ -26,10 +27,7 @@ use crate::{ | |||
26 | // let map = HashMap<|>::new(); | 27 | // let map = HashMap<|>::new(); |
27 | // } | 28 | // } |
28 | // ``` | 29 | // ``` |
29 | pub(crate) fn auto_import<F: ImportsLocator>( | 30 | pub(crate) fn auto_import(ctx: AssistCtx) -> Option<Assist> { |
30 | ctx: AssistCtx, | ||
31 | imports_locator: &mut F, | ||
32 | ) -> Option<Assist> { | ||
33 | let path_to_import: ast::Path = ctx.find_node_at_offset()?; | 31 | let path_to_import: ast::Path = ctx.find_node_at_offset()?; |
34 | let path_to_import_syntax = path_to_import.syntax(); | 32 | let path_to_import_syntax = path_to_import.syntax(); |
35 | if path_to_import_syntax.ancestors().find_map(ast::UseItem::cast).is_some() { | 33 | if path_to_import_syntax.ancestors().find_map(ast::UseItem::cast).is_some() { |
@@ -52,6 +50,8 @@ pub(crate) fn auto_import<F: ImportsLocator>( | |||
52 | return None; | 50 | return None; |
53 | } | 51 | } |
54 | 52 | ||
53 | let mut imports_locator = ImportsLocatorIde::new(ctx.db); | ||
54 | |||
55 | let proposed_imports = imports_locator | 55 | let proposed_imports = imports_locator |
56 | .find_imports(&name_to_import) | 56 | .find_imports(&name_to_import) |
57 | .into_iter() | 57 | .into_iter() |
@@ -81,16 +81,12 @@ fn import_to_action(import: ModPath, position: &SyntaxNode, anchor: &SyntaxNode) | |||
81 | #[cfg(test)] | 81 | #[cfg(test)] |
82 | mod tests { | 82 | mod tests { |
83 | use super::*; | 83 | use super::*; |
84 | use crate::helpers::{ | 84 | use crate::helpers::{check_assist, check_assist_not_applicable}; |
85 | check_assist_with_imports_locator, check_assist_with_imports_locator_not_applicable, | ||
86 | TestImportsLocator, | ||
87 | }; | ||
88 | 85 | ||
89 | #[test] | 86 | #[test] |
90 | fn applicable_when_found_an_import() { | 87 | fn applicable_when_found_an_import() { |
91 | check_assist_with_imports_locator( | 88 | check_assist( |
92 | auto_import, | 89 | auto_import, |
93 | TestImportsLocator::new, | ||
94 | r" | 90 | r" |
95 | <|>PubStruct | 91 | <|>PubStruct |
96 | 92 | ||
@@ -112,9 +108,8 @@ mod tests { | |||
112 | 108 | ||
113 | #[test] | 109 | #[test] |
114 | fn auto_imports_are_merged() { | 110 | fn auto_imports_are_merged() { |
115 | check_assist_with_imports_locator( | 111 | check_assist( |
116 | auto_import, | 112 | auto_import, |
117 | TestImportsLocator::new, | ||
118 | r" | 113 | r" |
119 | use PubMod::PubStruct1; | 114 | use PubMod::PubStruct1; |
120 | 115 | ||
@@ -148,9 +143,8 @@ mod tests { | |||
148 | 143 | ||
149 | #[test] | 144 | #[test] |
150 | fn applicable_when_found_multiple_imports() { | 145 | fn applicable_when_found_multiple_imports() { |
151 | check_assist_with_imports_locator( | 146 | check_assist( |
152 | auto_import, | 147 | auto_import, |
153 | TestImportsLocator::new, | ||
154 | r" | 148 | r" |
155 | PubSt<|>ruct | 149 | PubSt<|>ruct |
156 | 150 | ||
@@ -184,9 +178,8 @@ mod tests { | |||
184 | 178 | ||
185 | #[test] | 179 | #[test] |
186 | fn not_applicable_for_already_imported_types() { | 180 | fn not_applicable_for_already_imported_types() { |
187 | check_assist_with_imports_locator_not_applicable( | 181 | check_assist_not_applicable( |
188 | auto_import, | 182 | auto_import, |
189 | TestImportsLocator::new, | ||
190 | r" | 183 | r" |
191 | use PubMod::PubStruct; | 184 | use PubMod::PubStruct; |
192 | 185 | ||
@@ -201,9 +194,8 @@ mod tests { | |||
201 | 194 | ||
202 | #[test] | 195 | #[test] |
203 | fn not_applicable_for_types_with_private_paths() { | 196 | fn not_applicable_for_types_with_private_paths() { |
204 | check_assist_with_imports_locator_not_applicable( | 197 | check_assist_not_applicable( |
205 | auto_import, | 198 | auto_import, |
206 | TestImportsLocator::new, | ||
207 | r" | 199 | r" |
208 | PrivateStruct<|> | 200 | PrivateStruct<|> |
209 | 201 | ||
@@ -216,9 +208,8 @@ mod tests { | |||
216 | 208 | ||
217 | #[test] | 209 | #[test] |
218 | fn not_applicable_when_no_imports_found() { | 210 | fn not_applicable_when_no_imports_found() { |
219 | check_assist_with_imports_locator_not_applicable( | 211 | check_assist_not_applicable( |
220 | auto_import, | 212 | auto_import, |
221 | TestImportsLocator::new, | ||
222 | " | 213 | " |
223 | PubStruct<|>", | 214 | PubStruct<|>", |
224 | ); | 215 | ); |
@@ -226,9 +217,8 @@ mod tests { | |||
226 | 217 | ||
227 | #[test] | 218 | #[test] |
228 | fn not_applicable_in_import_statements() { | 219 | fn not_applicable_in_import_statements() { |
229 | check_assist_with_imports_locator_not_applicable( | 220 | check_assist_not_applicable( |
230 | auto_import, | 221 | auto_import, |
231 | TestImportsLocator::new, | ||
232 | r" | 222 | r" |
233 | use PubStruct<|>; | 223 | use PubStruct<|>; |
234 | 224 | ||
@@ -240,9 +230,8 @@ mod tests { | |||
240 | 230 | ||
241 | #[test] | 231 | #[test] |
242 | fn function_import() { | 232 | fn function_import() { |
243 | check_assist_with_imports_locator( | 233 | check_assist( |
244 | auto_import, | 234 | auto_import, |
245 | TestImportsLocator::new, | ||
246 | r" | 235 | r" |
247 | test_function<|> | 236 | test_function<|> |
248 | 237 | ||