aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-03-27 18:55:05 +0000
committerGitHub <[email protected]>2020-03-27 18:55:05 +0000
commita1fea0d34ee8f3436aefd87d4c133a7ff50ffbb0 (patch)
tree9afc05a20e5e51f757317a71906dc45a97861415 /crates/ra_syntax
parent75f6ab208a2b3e5fea9e8b6362df3fad7308a0d5 (diff)
parentf016d8b900792c8ae4fce268920edea3035b6559 (diff)
Merge #3745
3745: Fix merge-imports assist for wildcard imports r=matklad a=piotr-szpetkowski Refs #3728 Besides the case mentioned in issue merging two diff-prefix wildcard uses will now work as well e.g. ```rust use std::cell::*; use std::str::*; ``` will translate into: ```rust use std::{cell::*, str::*} ``` I'd also like to explore usage of the `merge-imports` for same-prefix uses to simplify redundancy, but it seems like an idea for another issue and I'm not sure if it's something that this assist should do e.g.: ```rust use std::cell::Cell; use std::cell::*; ``` into: ```rust use std::cell::*; ``` Co-authored-by: Piotr Szpetkowski <[email protected]>
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast/edit.rs5
-rw-r--r--crates/ra_syntax/src/ast/make.rs5
2 files changed, 8 insertions, 2 deletions
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 }