diff options
Diffstat (limited to 'crates/assists/src/handlers/auto_import.rs')
-rw-r--r-- | crates/assists/src/handlers/auto_import.rs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/crates/assists/src/handlers/auto_import.rs b/crates/assists/src/handlers/auto_import.rs index fa524ffd9..d3ee98e5f 100644 --- a/crates/assists/src/handlers/auto_import.rs +++ b/crates/assists/src/handlers/auto_import.rs | |||
@@ -13,7 +13,10 @@ use syntax::{ | |||
13 | SyntaxNode, | 13 | SyntaxNode, |
14 | }; | 14 | }; |
15 | 15 | ||
16 | use crate::{utils::insert_use, AssistContext, AssistId, AssistKind, Assists, GroupLabel}; | 16 | use crate::{ |
17 | utils::insert_use, utils::mod_path_to_ast, AssistContext, AssistId, AssistKind, Assists, | ||
18 | GroupLabel, | ||
19 | }; | ||
17 | 20 | ||
18 | // Assist: auto_import | 21 | // Assist: auto_import |
19 | // | 22 | // |
@@ -54,7 +57,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
54 | range, | 57 | range, |
55 | |builder| { | 58 | |builder| { |
56 | let new_syntax = | 59 | let new_syntax = |
57 | insert_use(&scope, import.to_ast_path(), ctx.config.insert_use.merge); | 60 | insert_use(&scope, mod_path_to_ast(&import), ctx.config.insert_use.merge); |
58 | builder.replace(syntax.text_range(), new_syntax.to_string()) | 61 | builder.replace(syntax.text_range(), new_syntax.to_string()) |
59 | }, | 62 | }, |
60 | ); | 63 | ); |
@@ -191,12 +194,16 @@ impl AutoImportAssets { | |||
191 | _ => Some(candidate), | 194 | _ => Some(candidate), |
192 | }) | 195 | }) |
193 | .filter_map(|candidate| match candidate { | 196 | .filter_map(|candidate| match candidate { |
194 | Either::Left(module_def) => { | 197 | Either::Left(module_def) => self.module_with_name_to_import.find_use_path_prefixed( |
195 | self.module_with_name_to_import.find_use_path_prefixed(db, module_def) | 198 | db, |
196 | } | 199 | module_def, |
197 | Either::Right(macro_def) => { | 200 | ctx.config.insert_use.prefix_kind, |
198 | self.module_with_name_to_import.find_use_path_prefixed(db, macro_def) | 201 | ), |
199 | } | 202 | Either::Right(macro_def) => self.module_with_name_to_import.find_use_path_prefixed( |
203 | db, | ||
204 | macro_def, | ||
205 | ctx.config.insert_use.prefix_kind, | ||
206 | ), | ||
200 | }) | 207 | }) |
201 | .filter(|use_path| !use_path.segments.is_empty()) | 208 | .filter(|use_path| !use_path.segments.is_empty()) |
202 | .take(20) | 209 | .take(20) |