diff options
Diffstat (limited to 'crates/ra_assists/src/assists')
-rw-r--r-- | crates/ra_assists/src/assists/auto_import.rs | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/crates/ra_assists/src/assists/auto_import.rs b/crates/ra_assists/src/assists/auto_import.rs index 932a52bff..0d15adb87 100644 --- a/crates/ra_assists/src/assists/auto_import.rs +++ b/crates/ra_assists/src/assists/auto_import.rs | |||
@@ -79,12 +79,8 @@ pub(crate) fn auto_import<F: ImportsLocator>( | |||
79 | fn import_to_action(import: String, position: &SyntaxNode, anchor: &SyntaxNode) -> ActionBuilder { | 79 | fn import_to_action(import: String, position: &SyntaxNode, anchor: &SyntaxNode) -> ActionBuilder { |
80 | let mut action_builder = ActionBuilder::default(); | 80 | let mut action_builder = ActionBuilder::default(); |
81 | action_builder.label(format!("Import `{}`", &import)); | 81 | action_builder.label(format!("Import `{}`", &import)); |
82 | auto_import_text_edit( | 82 | let import_segments = import.split("::").map(SmolStr::new).collect::<Vec<_>>(); |
83 | position, | 83 | auto_import_text_edit(position, anchor, &import_segments, action_builder.text_edit_builder()); |
84 | anchor, | ||
85 | &[SmolStr::new(import)], | ||
86 | action_builder.text_edit_builder(), | ||
87 | ); | ||
88 | action_builder | 84 | action_builder |
89 | } | 85 | } |
90 | 86 | ||
@@ -121,6 +117,34 @@ mod tests { | |||
121 | } | 117 | } |
122 | 118 | ||
123 | #[test] | 119 | #[test] |
120 | fn auto_imports_are_merged() { | ||
121 | check_assist_with_imports_locator( | ||
122 | auto_import, | ||
123 | TestImportsLocator::new, | ||
124 | r" | ||
125 | use PubMod::PubStruct1; | ||
126 | |||
127 | PubStruct2<|> | ||
128 | |||
129 | pub mod PubMod { | ||
130 | pub struct PubStruct1; | ||
131 | pub struct PubStruct2; | ||
132 | } | ||
133 | ", | ||
134 | r" | ||
135 | use PubMod::{PubStruct2, PubStruct1}; | ||
136 | |||
137 | PubStruct2<|> | ||
138 | |||
139 | pub mod PubMod { | ||
140 | pub struct PubStruct1; | ||
141 | pub struct PubStruct2; | ||
142 | } | ||
143 | ", | ||
144 | ); | ||
145 | } | ||
146 | |||
147 | #[test] | ||
124 | fn applicable_when_found_multiple_imports() { | 148 | fn applicable_when_found_multiple_imports() { |
125 | check_assist_with_imports_locator( | 149 | check_assist_with_imports_locator( |
126 | auto_import, | 150 | auto_import, |