aboutsummaryrefslogtreecommitdiff
path: root/crates/assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists')
-rw-r--r--crates/assists/src/handlers/replace_qualified_name_with_use.rs2
-rw-r--r--crates/assists/src/utils/insert_use.rs35
2 files changed, 33 insertions, 4 deletions
diff --git a/crates/assists/src/handlers/replace_qualified_name_with_use.rs b/crates/assists/src/handlers/replace_qualified_name_with_use.rs
index 74afc123b..e95b971a4 100644
--- a/crates/assists/src/handlers/replace_qualified_name_with_use.rs
+++ b/crates/assists/src/handlers/replace_qualified_name_with_use.rs
@@ -393,7 +393,7 @@ impl std::fmt::Display<|> for Foo {
393} 393}
394", 394",
395 r" 395 r"
396use std::fmt::{Display, nested::Debug}; 396use std::fmt::{nested::Debug, Display};
397 397
398impl Display for Foo { 398impl Display for Foo {
399} 399}
diff --git a/crates/assists/src/utils/insert_use.rs b/crates/assists/src/utils/insert_use.rs
index f6025c99a..bfd457d18 100644
--- a/crates/assists/src/utils/insert_use.rs
+++ b/crates/assists/src/utils/insert_use.rs
@@ -200,7 +200,18 @@ fn recursive_merge(
200 return None; 200 return None;
201 } 201 }
202 let rhs_path = rhs_t.path(); 202 let rhs_path = rhs_t.path();
203 match use_trees.binary_search_by(|p| path_cmp_bin_search(p.path(), rhs_path.clone())) { 203 match use_trees.binary_search_by(|lhs_t| {
204 let (lhs_t, rhs_t) = match lhs_t
205 .path()
206 .zip(rhs_path.clone())
207 .and_then(|(lhs, rhs)| common_prefix(&lhs, &rhs))
208 {
209 Some((lhs_p, rhs_p)) => (lhs_t.split_prefix(&lhs_p), rhs_t.split_prefix(&rhs_p)),
210 None => (lhs_t.clone(), rhs_t.clone()),
211 };
212
213 path_cmp_bin_search(lhs_t.path(), rhs_t.path())
214 }) {
204 Ok(idx) => { 215 Ok(idx) => {
205 let lhs_t = &mut use_trees[idx]; 216 let lhs_t = &mut use_trees[idx];
206 let lhs_path = lhs_t.path()?; 217 let lhs_path = lhs_t.path()?;
@@ -327,11 +338,11 @@ fn path_cmp_for_sort(a: Option<ast::Path>, b: Option<ast::Path>) -> Ordering {
327 338
328/// Path comparison func for binary searching for merging. 339/// Path comparison func for binary searching for merging.
329fn path_cmp_bin_search(lhs: Option<ast::Path>, rhs: Option<ast::Path>) -> Ordering { 340fn path_cmp_bin_search(lhs: Option<ast::Path>, rhs: Option<ast::Path>) -> Ordering {
330 match (lhs, rhs) { 341 match (lhs.and_then(|path| path.segment()), rhs.and_then(|path| path.segment())) {
331 (None, None) => Ordering::Equal, 342 (None, None) => Ordering::Equal,
332 (None, Some(_)) => Ordering::Less, 343 (None, Some(_)) => Ordering::Less,
333 (Some(_), None) => Ordering::Greater, 344 (Some(_), None) => Ordering::Greater,
334 (Some(ref a), Some(ref b)) => path_cmp_short(a, b), 345 (Some(ref a), Some(ref b)) => path_segment_cmp(a, b),
335 } 346 }
336} 347}
337 348
@@ -802,6 +813,24 @@ use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
802 } 813 }
803 814
804 #[test] 815 #[test]
816 fn merge_groups_full_nested_long() {
817 check_full(
818 "std::foo::bar::Baz",
819 r"use std::{foo::bar::Qux};",
820 r"use std::{foo::bar::{Baz, Qux}};",
821 );
822 }
823
824 #[test]
825 fn merge_groups_last_nested_long() {
826 check_full(
827 "std::foo::bar::Baz",
828 r"use std::{foo::bar::Qux};",
829 r"use std::{foo::bar::{Baz, Qux}};",
830 );
831 }
832
833 #[test]
805 fn merge_groups_skip_pub() { 834 fn merge_groups_skip_pub() {
806 check_full( 835 check_full(
807 "std::io", 836 "std::io",