aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/handlers/merge_imports.rs27
-rw-r--r--crates/syntax/src/ast/edit.rs11
-rw-r--r--crates/syntax/src/ast/make.rs3
3 files changed, 38 insertions, 3 deletions
diff --git a/crates/ra_assists/src/handlers/merge_imports.rs b/crates/ra_assists/src/handlers/merge_imports.rs
index 9c5c6eda7..47d465404 100644
--- a/crates/ra_assists/src/handlers/merge_imports.rs
+++ b/crates/ra_assists/src/handlers/merge_imports.rs
@@ -165,6 +165,33 @@ use std::fmt::{Display, Debug};
165 } 165 }
166 166
167 #[test] 167 #[test]
168 fn merge_self1() {
169 check_assist(
170 merge_imports,
171 r"
172use std::fmt<|>;
173use std::fmt::Display;
174",
175 r"
176use std::fmt::{self, Display};
177",
178 );
179 }
180
181 #[test]
182 fn merge_self2() {
183 check_assist(
184 merge_imports,
185 r"
186use std::{fmt, <|>fmt::Display};
187",
188 r"
189use std::{fmt::{Display, self}};
190",
191 );
192 }
193
194 #[test]
168 fn test_merge_nested() { 195 fn test_merge_nested() {
169 check_assist( 196 check_assist(
170 merge_imports, 197 merge_imports,
diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs
index 5ed123f91..2667d9af4 100644
--- a/crates/syntax/src/ast/edit.rs
+++ b/crates/syntax/src/ast/edit.rs
@@ -313,10 +313,15 @@ impl ast::UseTree {
313 313
314 #[must_use] 314 #[must_use]
315 pub fn split_prefix(&self, prefix: &ast::Path) -> ast::UseTree { 315 pub fn split_prefix(&self, prefix: &ast::Path) -> ast::UseTree {
316 let suffix = match split_path_prefix(&prefix) { 316 let suffix = if self.path().as_ref() == Some(prefix) && self.use_tree_list().is_none() {
317 Some(it) => it, 317 make::path_unqualified(make::path_segment_self())
318 None => return self.clone(), 318 } else {
319 match split_path_prefix(&prefix) {
320 Some(it) => it,
321 None => return self.clone(),
322 }
319 }; 323 };
324
320 let use_tree = make::use_tree( 325 let use_tree = make::use_tree(
321 suffix, 326 suffix,
322 self.use_tree_list(), 327 self.use_tree_list(),
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index 254a37fe3..3009faed7 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -24,6 +24,9 @@ pub fn ty(text: &str) -> ast::Type {
24pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment { 24pub fn path_segment(name_ref: ast::NameRef) -> ast::PathSegment {
25 ast_from_text(&format!("use {};", name_ref)) 25 ast_from_text(&format!("use {};", name_ref))
26} 26}
27pub fn path_segment_self() -> ast::PathSegment {
28 ast_from_text("use self;")
29}
27pub fn path_unqualified(segment: ast::PathSegment) -> ast::Path { 30pub fn path_unqualified(segment: ast::PathSegment) -> ast::Path {
28 path_from_text(&format!("use {}", segment)) 31 path_from_text(&format!("use {}", segment))
29} 32}