From aa69757a01c26cfad12498053c55cbc3d66a4bdb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 23 Jun 2020 22:27:24 +0200 Subject: More principled indentation trimming in fixtures --- crates/ra_assists/src/handlers/add_function.rs | 1 - crates/ra_assists/src/handlers/auto_import.rs | 92 ++++++------- crates/ra_assists/src/handlers/fix_visibility.rs | 157 ++++++++++++----------- 3 files changed, 127 insertions(+), 123 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/handlers/add_function.rs b/crates/ra_assists/src/handlers/add_function.rs index 1cfbd75aa..19ce81d99 100644 --- a/crates/ra_assists/src/handlers/add_function.rs +++ b/crates/ra_assists/src/handlers/add_function.rs @@ -986,7 +986,6 @@ fn main() { ", r" - pub(crate) fn bar() { ${0:todo!()} }", diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs index 5092bf336..d1cafa7d9 100644 --- a/crates/ra_assists/src/handlers/auto_import.rs +++ b/crates/ra_assists/src/handlers/auto_import.rs @@ -488,16 +488,17 @@ mod tests { check_assist( auto_import, r" - //- /lib.rs crate:crate_with_macro - #[macro_export] - macro_rules! foo { - () => () - } +//- /lib.rs crate:crate_with_macro +#[macro_export] +macro_rules! foo { + () => () +} - //- /main.rs crate:main deps:crate_with_macro - fn main() { - foo<|> - }", +//- /main.rs crate:main deps:crate_with_macro +fn main() { + foo<|> +} +", r"use crate_with_macro::foo; fn main() { @@ -847,13 +848,14 @@ fn main() { check_assist( auto_import, r" - //- /lib.rs crate:dep - pub struct Struct; +//- /lib.rs crate:dep +pub struct Struct; - //- /main.rs crate:main deps:dep - fn main() { - Struct<|> - }", +//- /main.rs crate:main deps:dep +fn main() { + Struct<|> +} +", r"use dep::Struct; fn main() { @@ -869,20 +871,22 @@ fn main() { check_assist( auto_import, r" - //- /lib.rs crate:dep - pub mod fmt { - pub trait Display {} - } +//- /lib.rs crate:dep +pub mod fmt { + pub trait Display {} +} - pub fn panic_fmt() {} +pub fn panic_fmt() {} - //- /main.rs crate:main deps:dep - struct S; +//- /main.rs crate:main deps:dep +struct S; - impl f<|>mt::Display for S {}", +impl f<|>mt::Display for S {} +", r"use dep::fmt; struct S; + impl fmt::Display for S {} ", ); @@ -894,21 +898,20 @@ impl fmt::Display for S {} check_assist( auto_import, r" - //- /lib.rs crate:dep - - macro_rules! mac { - () => { - pub struct Cheese; - }; - } - - mac!(); +//- /lib.rs crate:dep +macro_rules! mac { + () => { + pub struct Cheese; + }; +} - //- /main.rs crate:main deps:dep +mac!(); - fn main() { - Cheese<|>; - }", +//- /main.rs crate:main deps:dep +fn main() { + Cheese<|>; +} +", r"use dep::Cheese; fn main() { @@ -924,16 +927,15 @@ fn main() { check_assist( auto_import, r" - //- /lib.rs crate:dep - - pub struct FMT; - pub struct fmt; - - //- /main.rs crate:main deps:dep +//- /lib.rs crate:dep +pub struct FMT; +pub struct fmt; - fn main() { - FMT<|>; - }", +//- /main.rs crate:main deps:dep +fn main() { + FMT<|>; +} +", r"use dep::FMT; fn main() { diff --git a/crates/ra_assists/src/handlers/fix_visibility.rs b/crates/ra_assists/src/handlers/fix_visibility.rs index 531b3560f..54601d1f3 100644 --- a/crates/ra_assists/src/handlers/fix_visibility.rs +++ b/crates/ra_assists/src/handlers/fix_visibility.rs @@ -255,15 +255,14 @@ mod tests { check_assist( fix_visibility, r" - //- /main.rs - mod foo; - fn main() { foo::Foo<|> } +//- /main.rs +mod foo; +fn main() { foo::Foo<|> } - //- /foo.rs - struct Foo; - ", +//- /foo.rs +struct Foo; +", r"$0pub(crate) struct Foo; - ", ); } @@ -279,14 +278,14 @@ mod tests { ); check_assist( fix_visibility, - r"//- /lib.rs - mod foo; - fn main() { foo::Foo { <|>bar: () }; } - //- /foo.rs - pub struct Foo { bar: () } - ", + r" +//- /lib.rs +mod foo; +fn main() { foo::Foo { <|>bar: () }; } +//- /foo.rs +pub struct Foo { bar: () } +", r"pub struct Foo { $0pub(crate) bar: () } - ", ); check_assist_not_applicable( @@ -296,12 +295,13 @@ mod tests { ); check_assist_not_applicable( fix_visibility, - r"//- /lib.rs - mod foo; - fn main() { foo::Foo { <|>bar: () }; } - //- /foo.rs - pub struct Foo { pub bar: () } - ", + r" +//- /lib.rs +mod foo; +fn main() { foo::Foo { <|>bar: () }; } +//- /foo.rs +pub struct Foo { pub bar: () } +", ); } @@ -316,14 +316,14 @@ mod tests { ); check_assist( fix_visibility, - r"//- /lib.rs - mod foo; - fn main() { foo::Foo::Bar { <|>bar: () }; } - //- /foo.rs - pub enum Foo { Bar { bar: () } } - ", + r" +//- /lib.rs +mod foo; +fn main() { foo::Foo::Bar { <|>bar: () }; } +//- /foo.rs +pub enum Foo { Bar { bar: () } } +", r"pub enum Foo { Bar { $0pub(crate) bar: () } } - ", ); check_assist_not_applicable( @@ -333,12 +333,13 @@ mod tests { ); check_assist_not_applicable( fix_visibility, - r"//- /lib.rs - mod foo; - fn main() { foo::Foo { <|>bar: () }; } - //- /foo.rs - pub struct Foo { pub bar: () } - ", + r" +//- /lib.rs +mod foo; +fn main() { foo::Foo { <|>bar: () }; } +//- /foo.rs +pub struct Foo { pub bar: () } +", ); } @@ -355,14 +356,14 @@ mod tests { ); check_assist( fix_visibility, - r"//- /lib.rs - mod foo; - fn main() { foo::Foo { <|>bar: () }; } - //- /foo.rs - pub union Foo { bar: () } - ", + r" +//- /lib.rs +mod foo; +fn main() { foo::Foo { <|>bar: () }; } +//- /foo.rs +pub union Foo { bar: () } +", r"pub union Foo { $0pub(crate) bar: () } - ", ); check_assist_not_applicable( @@ -372,12 +373,13 @@ mod tests { ); check_assist_not_applicable( fix_visibility, - r"//- /lib.rs - mod foo; - fn main() { foo::Foo { <|>bar: () }; } - //- /foo.rs - pub union Foo { pub bar: () } - ", + r" +//- /lib.rs +mod foo; +fn main() { foo::Foo { <|>bar: () }; } +//- /foo.rs +pub union Foo { pub bar: () } +", ); } @@ -458,19 +460,18 @@ mod tests { check_assist( fix_visibility, r" - //- /main.rs - mod foo; - fn main() { foo::bar<|>::baz(); } +//- /main.rs +mod foo; +fn main() { foo::bar<|>::baz(); } - //- /foo.rs - mod bar { - pub fn baz() {} - } - ", +//- /foo.rs +mod bar { + pub fn baz() {} +} +", r"$0pub(crate) mod bar { pub fn baz() {} } - ", ); @@ -486,17 +487,15 @@ mod tests { check_assist( fix_visibility, r" - //- /main.rs - mod foo; - fn main() { foo::bar<|>::baz(); } - - //- /foo.rs - mod bar; - - //- /foo/bar.rs - pub fn baz() {} - } - ", +//- /main.rs +mod foo; +fn main() { foo::bar<|>::baz(); } + +//- /foo.rs +mod bar; +//- /foo/bar.rs +pub fn baz() {} +", r"$0pub(crate) mod bar; ", ); @@ -506,14 +505,16 @@ mod tests { fn fix_visibility_of_module_declaration_in_other_file() { check_assist( fix_visibility, - r"//- /main.rs - mod foo; - fn main() { foo::bar<|>>::baz(); } + r" +//- /main.rs +mod foo; +fn main() { foo::bar<|>>::baz(); } - //- /foo.rs - mod bar { - pub fn baz() {} - }", +//- /foo.rs +mod bar { + pub fn baz() {} +} +", r"$0pub(crate) mod bar { pub fn baz() {} } @@ -525,10 +526,12 @@ mod tests { fn adds_pub_when_target_is_in_another_crate() { check_assist( fix_visibility, - r"//- /main.rs crate:a deps:foo - foo::Bar<|> - //- /lib.rs crate:foo - struct Bar;", + r" +//- /main.rs crate:a deps:foo +foo::Bar<|> +//- /lib.rs crate:foo +struct Bar; +", r"$0pub struct Bar; ", ) -- cgit v1.2.3