diff options
Diffstat (limited to 'crates/ra_assists/src/assists')
-rw-r--r-- | crates/ra_assists/src/assists/add_import.rs | 9 | ||||
-rw-r--r-- | crates/ra_assists/src/assists/auto_import.rs | 9 |
2 files changed, 8 insertions, 10 deletions
diff --git a/crates/ra_assists/src/assists/add_import.rs b/crates/ra_assists/src/assists/add_import.rs index bf6cfe865..96a494c93 100644 --- a/crates/ra_assists/src/assists/add_import.rs +++ b/crates/ra_assists/src/assists/add_import.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use hir::{self, db::HirDatabase}; | 1 | use hir::{self, db::HirDatabase, ModPath}; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | ast::{self, NameOwner}, | 3 | ast::{self, NameOwner}, |
4 | AstNode, Direction, SmolStr, | 4 | AstNode, Direction, SmolStr, |
@@ -21,9 +21,10 @@ pub fn auto_import_text_edit( | |||
21 | // The statement to use as anchor (last resort) | 21 | // The statement to use as anchor (last resort) |
22 | anchor: &SyntaxNode, | 22 | anchor: &SyntaxNode, |
23 | // The path to import as a sequence of strings | 23 | // The path to import as a sequence of strings |
24 | target: &[SmolStr], | 24 | path_to_import: &ModPath, |
25 | edit: &mut TextEditBuilder, | 25 | edit: &mut TextEditBuilder, |
26 | ) { | 26 | ) { |
27 | let target = path_to_import.to_string().split("::").map(SmolStr::new).collect::<Vec<_>>(); | ||
27 | let container = position.ancestors().find_map(|n| { | 28 | let container = position.ancestors().find_map(|n| { |
28 | if let Some(module) = ast::Module::cast(n.clone()) { | 29 | if let Some(module) = ast::Module::cast(n.clone()) { |
29 | return module.item_list().map(|it| it.syntax().clone()); | 30 | return module.item_list().map(|it| it.syntax().clone()); |
@@ -32,8 +33,8 @@ pub fn auto_import_text_edit( | |||
32 | }); | 33 | }); |
33 | 34 | ||
34 | if let Some(container) = container { | 35 | if let Some(container) = container { |
35 | let action = best_action_for_target(container, anchor.clone(), target); | 36 | let action = best_action_for_target(container, anchor.clone(), &target); |
36 | make_assist(&action, target, edit); | 37 | make_assist(&action, &target, edit); |
37 | } | 38 | } |
38 | } | 39 | } |
39 | 40 | ||
diff --git a/crates/ra_assists/src/assists/auto_import.rs b/crates/ra_assists/src/assists/auto_import.rs index 0d15adb87..9e874aebb 100644 --- a/crates/ra_assists/src/assists/auto_import.rs +++ b/crates/ra_assists/src/assists/auto_import.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | use hir::db::HirDatabase; | 1 | use hir::{db::HirDatabase, ModPath}; |
2 | use ra_syntax::{ | 2 | use ra_syntax::{ |
3 | ast::{self, AstNode}, | 3 | ast::{self, AstNode}, |
4 | SmolStr, | ||
5 | SyntaxKind::USE_ITEM, | 4 | SyntaxKind::USE_ITEM, |
6 | SyntaxNode, | 5 | SyntaxNode, |
7 | }; | 6 | }; |
@@ -58,7 +57,6 @@ pub(crate) fn auto_import<F: ImportsLocator>( | |||
58 | .filter_map(|module_def| module_with_name_to_import.find_use_path(ctx.db, module_def)) | 57 | .filter_map(|module_def| module_with_name_to_import.find_use_path(ctx.db, module_def)) |
59 | .filter(|use_path| !use_path.segments.is_empty()) | 58 | .filter(|use_path| !use_path.segments.is_empty()) |
60 | .take(20) | 59 | .take(20) |
61 | .map(|import| import.to_string()) | ||
62 | .collect::<std::collections::BTreeSet<_>>(); | 60 | .collect::<std::collections::BTreeSet<_>>(); |
63 | if proposed_imports.is_empty() { | 61 | if proposed_imports.is_empty() { |
64 | return None; | 62 | return None; |
@@ -76,11 +74,10 @@ pub(crate) fn auto_import<F: ImportsLocator>( | |||
76 | ) | 74 | ) |
77 | } | 75 | } |
78 | 76 | ||
79 | fn import_to_action(import: String, position: &SyntaxNode, anchor: &SyntaxNode) -> ActionBuilder { | 77 | fn import_to_action(import: ModPath, position: &SyntaxNode, anchor: &SyntaxNode) -> ActionBuilder { |
80 | let mut action_builder = ActionBuilder::default(); | 78 | let mut action_builder = ActionBuilder::default(); |
81 | action_builder.label(format!("Import `{}`", &import)); | 79 | action_builder.label(format!("Import `{}`", &import)); |
82 | let import_segments = import.split("::").map(SmolStr::new).collect::<Vec<_>>(); | 80 | auto_import_text_edit(position, anchor, &import, action_builder.text_edit_builder()); |
83 | auto_import_text_edit(position, anchor, &import_segments, action_builder.text_edit_builder()); | ||
84 | action_builder | 81 | action_builder |
85 | } | 82 | } |
86 | 83 | ||