diff options
-rw-r--r-- | crates/ra_assists/src/handlers/merge_imports.rs | 28 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/edit.rs | 5 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 5 |
3 files changed, 36 insertions, 2 deletions
diff --git a/crates/ra_assists/src/handlers/merge_imports.rs b/crates/ra_assists/src/handlers/merge_imports.rs index 9c57d1e30..5d4b74e56 100644 --- a/crates/ra_assists/src/handlers/merge_imports.rs +++ b/crates/ra_assists/src/handlers/merge_imports.rs | |||
@@ -171,6 +171,34 @@ use std::{fmt::<|>{Display, Debug}}; | |||
171 | } | 171 | } |
172 | 172 | ||
173 | #[test] | 173 | #[test] |
174 | fn test_merge_single_wildcard_diff_prefixes() { | ||
175 | check_assist( | ||
176 | merge_imports, | ||
177 | r" | ||
178 | use std<|>::cell::*; | ||
179 | use std::str; | ||
180 | ", | ||
181 | r" | ||
182 | use std<|>::{cell::*, str}; | ||
183 | ", | ||
184 | ) | ||
185 | } | ||
186 | |||
187 | #[test] | ||
188 | fn test_merge_both_wildcard_diff_prefixes() { | ||
189 | check_assist( | ||
190 | merge_imports, | ||
191 | r" | ||
192 | use std<|>::cell::*; | ||
193 | use std::str::*; | ||
194 | ", | ||
195 | r" | ||
196 | use std<|>::{cell::*, str::*}; | ||
197 | ", | ||
198 | ) | ||
199 | } | ||
200 | |||
201 | #[test] | ||
174 | fn removes_just_enough_whitespace() { | 202 | fn removes_just_enough_whitespace() { |
175 | check_assist( | 203 | check_assist( |
176 | merge_imports, | 204 | merge_imports, |
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index bdaecdc43..2304e00cf 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs | |||
@@ -302,9 +302,10 @@ impl ast::UseTree { | |||
302 | Some(it) => it, | 302 | Some(it) => it, |
303 | None => return self.clone(), | 303 | None => return self.clone(), |
304 | }; | 304 | }; |
305 | let use_tree = make::use_tree(suffix.clone(), self.use_tree_list(), self.alias()); | 305 | let use_tree = |
306 | make::use_tree(suffix.clone(), self.use_tree_list(), self.alias(), self.has_star()); | ||
306 | let nested = make::use_tree_list(iter::once(use_tree)); | 307 | let nested = make::use_tree_list(iter::once(use_tree)); |
307 | return make::use_tree(prefix.clone(), Some(nested), None); | 308 | return make::use_tree(prefix.clone(), Some(nested), None, false); |
308 | 309 | ||
309 | fn split_path_prefix(prefix: &ast::Path) -> Option<ast::Path> { | 310 | fn split_path_prefix(prefix: &ast::Path) -> Option<ast::Path> { |
310 | let parent = prefix.parent_path()?; | 311 | let parent = prefix.parent_path()?; |
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 4621c9888..dbf8e6370 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -29,12 +29,17 @@ pub fn use_tree( | |||
29 | path: ast::Path, | 29 | path: ast::Path, |
30 | use_tree_list: Option<ast::UseTreeList>, | 30 | use_tree_list: Option<ast::UseTreeList>, |
31 | alias: Option<ast::Alias>, | 31 | alias: Option<ast::Alias>, |
32 | add_star: bool, | ||
32 | ) -> ast::UseTree { | 33 | ) -> ast::UseTree { |
33 | let mut buf = "use ".to_string(); | 34 | let mut buf = "use ".to_string(); |
34 | buf += &path.syntax().to_string(); | 35 | buf += &path.syntax().to_string(); |
35 | if let Some(use_tree_list) = use_tree_list { | 36 | if let Some(use_tree_list) = use_tree_list { |
36 | buf += &format!("::{}", use_tree_list); | 37 | buf += &format!("::{}", use_tree_list); |
37 | } | 38 | } |
39 | if add_star { | ||
40 | buf += "::*"; | ||
41 | } | ||
42 | |||
38 | if let Some(alias) = alias { | 43 | if let Some(alias) = alias { |
39 | buf += &format!(" {}", alias); | 44 | buf += &format!(" {}", alias); |
40 | } | 45 | } |