From a898752881779a328462ad9f2db291073f2f134f Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 12 Sep 2020 19:18:14 +0200 Subject: Reimplement import merging by making it recursive properly nesting all levels --- crates/assists/src/handlers/merge_imports.rs | 14 ++++++++------ .../src/handlers/replace_qualified_name_with_use.rs | 20 +++++++------------- 2 files changed, 15 insertions(+), 19 deletions(-) (limited to 'crates/assists/src/handlers') diff --git a/crates/assists/src/handlers/merge_imports.rs b/crates/assists/src/handlers/merge_imports.rs index 0bd679260..fe33cee53 100644 --- a/crates/assists/src/handlers/merge_imports.rs +++ b/crates/assists/src/handlers/merge_imports.rs @@ -95,7 +95,7 @@ use std::fmt::Debug; use std::fmt<|>::Display; ", r" -use std::fmt::{Display, Debug}; +use std::fmt::{Debug, Display}; ", ); } @@ -122,7 +122,7 @@ use std::fmt::{self, Display}; use std::{fmt, <|>fmt::Display}; ", r" -use std::{fmt::{Display, self}}; +use std::{fmt::{self, Display}}; ", ); } @@ -210,13 +210,17 @@ use std::{fmt<|>::Debug, fmt::Display}; use std::{fmt::{Debug, Display}}; ", ); + } + + #[test] + fn test_merge_nested2() { check_assist( merge_imports, r" use std::{fmt::Debug, fmt<|>::Display}; ", r" -use std::{fmt::{Display, Debug}}; +use std::{fmt::{Debug, Display}}; ", ); } @@ -310,9 +314,7 @@ use foo::<|>{ }; ", r" -use foo::{ - FooBar, -bar::baz}; +use foo::{FooBar, bar::baz}; ", ) } 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 85c70d16b..093c3b101 100644 --- a/crates/assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/assists/src/handlers/replace_qualified_name_with_use.rs @@ -312,7 +312,7 @@ impl std::fmt<|> for Foo { } ", r" -use std::fmt::{Debug, self}; +use std::fmt::{self, Debug}; impl fmt for Foo { } @@ -330,9 +330,8 @@ use std::fmt::{Debug, nested::{Display}}; impl std::fmt::nested<|> for Foo { } ", - // FIXME(veykril): should be nested::{self, Display} here r" -use std::fmt::{Debug, nested::{Display}, nested}; +use std::fmt::{Debug, nested::{self, Display}}; impl nested for Foo { } @@ -350,9 +349,8 @@ use std::fmt::{Debug, nested::{self, Display}}; impl std::fmt::nested<|> for Foo { } ", - // FIXME(veykril): nested is duplicated now r" -use std::fmt::{Debug, nested::{self, Display}, nested}; +use std::fmt::{Debug, nested::{self, Display}}; impl nested for Foo { } @@ -371,7 +369,7 @@ impl std::fmt::nested::Debug<|> for Foo { } ", r" -use std::fmt::{Debug, nested::{Display}, nested::Debug}; +use std::fmt::{Debug, nested::{Debug, Display}}; impl Debug for Foo { } @@ -409,7 +407,7 @@ impl std::fmt::Display<|> for Foo { } ", r" -use std::fmt::{nested::Debug, Display}; +use std::fmt::{Display, nested::Debug}; impl Display for Foo { } @@ -429,12 +427,8 @@ use crate::{ fn foo() { crate::ty::lower<|>::trait_env() } ", - // FIXME(veykril): formatting broke here r" -use crate::{ - ty::{Substs, Ty}, - AssocItem, -ty::lower}; +use crate::{AssocItem, ty::{Substs, Ty, lower}}; fn foo() { lower::trait_env() } ", @@ -633,7 +627,7 @@ fn main() { } ", r" -use std::fmt::{Display, self}; +use std::fmt::{self, Display}; fn main() { fmt; -- cgit v1.2.3