Skip to content

Commit a898752

Browse files
committed
Reimplement import merging by making it recursive properly nesting all levels
1 parent c862346 commit a898752

File tree

4 files changed

+264
-83
lines changed

4 files changed

+264
-83
lines changed

crates/assists/src/handlers/merge_imports.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ use std::fmt::Debug;
9595
use std::fmt<|>::Display;
9696
",
9797
r"
98-
use std::fmt::{Display, Debug};
98+
use std::fmt::{Debug, Display};
9999
",
100100
);
101101
}
@@ -122,7 +122,7 @@ use std::fmt::{self, Display};
122122
use std::{fmt, <|>fmt::Display};
123123
",
124124
r"
125-
use std::{fmt::{Display, self}};
125+
use std::{fmt::{self, Display}};
126126
",
127127
);
128128
}
@@ -210,13 +210,17 @@ use std::{fmt<|>::Debug, fmt::Display};
210210
use std::{fmt::{Debug, Display}};
211211
",
212212
);
213+
}
214+
215+
#[test]
216+
fn test_merge_nested2() {
213217
check_assist(
214218
merge_imports,
215219
r"
216220
use std::{fmt::Debug, fmt<|>::Display};
217221
",
218222
r"
219-
use std::{fmt::{Display, Debug}};
223+
use std::{fmt::{Debug, Display}};
220224
",
221225
);
222226
}
@@ -310,9 +314,7 @@ use foo::<|>{
310314
};
311315
",
312316
r"
313-
use foo::{
314-
FooBar,
315-
bar::baz};
317+
use foo::{FooBar, bar::baz};
316318
",
317319
)
318320
}

crates/assists/src/handlers/replace_qualified_name_with_use.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ impl std::fmt<|> for Foo {
312312
}
313313
",
314314
r"
315-
use std::fmt::{Debug, self};
315+
use std::fmt::{self, Debug};
316316
317317
impl fmt for Foo {
318318
}
@@ -330,9 +330,8 @@ use std::fmt::{Debug, nested::{Display}};
330330
impl std::fmt::nested<|> for Foo {
331331
}
332332
",
333-
// FIXME(veykril): should be nested::{self, Display} here
334333
r"
335-
use std::fmt::{Debug, nested::{Display}, nested};
334+
use std::fmt::{Debug, nested::{self, Display}};
336335
337336
impl nested for Foo {
338337
}
@@ -350,9 +349,8 @@ use std::fmt::{Debug, nested::{self, Display}};
350349
impl std::fmt::nested<|> for Foo {
351350
}
352351
",
353-
// FIXME(veykril): nested is duplicated now
354352
r"
355-
use std::fmt::{Debug, nested::{self, Display}, nested};
353+
use std::fmt::{Debug, nested::{self, Display}};
356354
357355
impl nested for Foo {
358356
}
@@ -371,7 +369,7 @@ impl std::fmt::nested::Debug<|> for Foo {
371369
}
372370
",
373371
r"
374-
use std::fmt::{Debug, nested::{Display}, nested::Debug};
372+
use std::fmt::{Debug, nested::{Debug, Display}};
375373
376374
impl Debug for Foo {
377375
}
@@ -409,7 +407,7 @@ impl std::fmt::Display<|> for Foo {
409407
}
410408
",
411409
r"
412-
use std::fmt::{nested::Debug, Display};
410+
use std::fmt::{Display, nested::Debug};
413411
414412
impl Display for Foo {
415413
}
@@ -429,12 +427,8 @@ use crate::{
429427
430428
fn foo() { crate::ty::lower<|>::trait_env() }
431429
",
432-
// FIXME(veykril): formatting broke here
433430
r"
434-
use crate::{
435-
ty::{Substs, Ty},
436-
AssocItem,
437-
ty::lower};
431+
use crate::{AssocItem, ty::{Substs, Ty, lower}};
438432
439433
fn foo() { lower::trait_env() }
440434
",
@@ -633,7 +627,7 @@ fn main() {
633627
}
634628
",
635629
r"
636-
use std::fmt::{Display, self};
630+
use std::fmt::{self, Display};
637631
638632
fn main() {
639633
fmt;

0 commit comments

Comments
 (0)