Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/handlers/add_missing_impl_members.rs')
-rw-r--r--crates/ide-assists/src/handlers/add_missing_impl_members.rs172
1 files changed, 168 insertions, 4 deletions
diff --git a/crates/ide-assists/src/handlers/add_missing_impl_members.rs b/crates/ide-assists/src/handlers/add_missing_impl_members.rs
index 9e4e6c1daf..89e03a98d6 100644
--- a/crates/ide-assists/src/handlers/add_missing_impl_members.rs
+++ b/crates/ide-assists/src/handlers/add_missing_impl_members.rs
@@ -1346,8 +1346,8 @@ struct SomeStruct {
}
impl PartialEq for SomeStruct {
$0fn ne(&self, other: &Self) -> bool {
- !self.eq(other)
- }
+ !self.eq(other)
+ }
}
"#,
);
@@ -1511,11 +1511,175 @@ fn main() {
struct S;
impl Tr for S {
fn method() {
- ${0:todo!()}
- }
+ ${0:todo!()}
+ }
}
}
"#,
);
}
+
+ #[test]
+ fn test_add_missing_preserves_indentation() {
+ // in different modules
+ check_assist(
+ add_missing_impl_members,
+ r#"
+mod m {
+ pub trait Foo {
+ const CONST_MULTILINE: (
+ i32,
+ i32
+ );
+
+ fn foo(&self);
+ }
+}
+struct S;
+impl m::Foo for S { $0 }"#,
+ r#"
+mod m {
+ pub trait Foo {
+ const CONST_MULTILINE: (
+ i32,
+ i32
+ );
+
+ fn foo(&self);
+ }
+}
+struct S;
+impl m::Foo for S {
+ $0const CONST_MULTILINE: (
+ i32,
+ i32
+ );
+
+ fn foo(&self) {
+ todo!()
+ }
+}"#,
+ );
+ // in the same module
+ check_assist(
+ add_missing_impl_members,
+ r#"
+mod m {
+ trait Foo {
+ type Output;
+
+ const CONST: usize = 42;
+ const CONST_2: i32;
+ const CONST_MULTILINE: (
+ i32,
+ i32
+ );
+
+ fn foo(&self);
+ fn bar(&self);
+ fn baz(&self);
+ }
+
+ struct S;
+
+ impl Foo for S {
+ fn bar(&self) {}
+$0
+ }
+}"#,
+ r#"
+mod m {
+ trait Foo {
+ type Output;
+
+ const CONST: usize = 42;
+ const CONST_2: i32;
+ const CONST_MULTILINE: (
+ i32,
+ i32
+ );
+
+ fn foo(&self);
+ fn bar(&self);
+ fn baz(&self);
+ }
+
+ struct S;
+
+ impl Foo for S {
+ fn bar(&self) {}
+
+ $0type Output;
+
+ const CONST_2: i32;
+
+ const CONST_MULTILINE: (
+ i32,
+ i32
+ );
+
+ fn foo(&self) {
+ todo!()
+ }
+
+ fn baz(&self) {
+ todo!()
+ }
+
+ }
+}"#,
+ );
+ }
+
+ #[test]
+ fn test_add_default_preserves_indentation() {
+ check_assist(
+ add_missing_default_members,
+ r#"
+mod m {
+ pub trait Foo {
+ type Output;
+
+ const CONST: usize = 42;
+ const CONST_2: i32;
+ const CONST_MULTILINE: = (
+ i32,
+ i32,
+ ) = (3, 14);
+
+ fn valid(some: u32) -> bool { false }
+ fn foo(some: u32) -> bool;
+ }
+}
+struct S;
+impl m::Foo for S { $0 }"#,
+ r#"
+mod m {
+ pub trait Foo {
+ type Output;
+
+ const CONST: usize = 42;
+ const CONST_2: i32;
+ const CONST_MULTILINE: = (
+ i32,
+ i32,
+ ) = (3, 14);
+
+ fn valid(some: u32) -> bool { false }
+ fn foo(some: u32) -> bool;
+ }
+}
+struct S;
+impl m::Foo for S {
+ $0const CONST: usize = 42;
+
+ const CONST_MULTILINE: = (
+ i32,
+ i32,
+ ) = (3, 14);
+
+ fn valid(some: u32) -> bool { false }
+}"#,
+ )
+ }
}