aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorgfreezy <[email protected]>2019-03-23 14:49:20 +0000
committergfreezy <[email protected]>2019-03-23 14:49:20 +0000
commitd99ae9ba56ac3ca2a07dc5b587b5a3c0dd504762 (patch)
tree4180f8764bc6e4a0f1d49055cf344755deddd8ed /crates
parent6e324d38d6ef3e250ff32a397f4777699e006f7f (diff)
Add impl members assist shold not copy docstrings, attrs and default methods.
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/add_missing_impl_members.rs64
1 files changed, 42 insertions, 22 deletions
diff --git a/crates/ra_assists/src/add_missing_impl_members.rs b/crates/ra_assists/src/add_missing_impl_members.rs
index 4435c4b5d..b09478d30 100644
--- a/crates/ra_assists/src/add_missing_impl_members.rs
+++ b/crates/ra_assists/src/add_missing_impl_members.rs
@@ -35,6 +35,7 @@ pub(crate) fn add_missing_impl_members(mut ctx: AssistCtx<impl HirDatabase>) ->
35 trait_fns 35 trait_fns
36 .into_iter() 36 .into_iter()
37 .filter(|t| def_name(t).is_some()) 37 .filter(|t| def_name(t).is_some())
38 .filter(|t| t.body().is_none())
38 .filter(|t| impl_fns.iter().all(|i| def_name(i) != def_name(t))) 39 .filter(|t| impl_fns.iter().all(|i| def_name(i) != def_name(t)))
39 .collect() 40 .collect()
40 }; 41 };
@@ -103,11 +104,13 @@ fn build_func_body(def: &ast::FnDef) -> String {
103 let mut buf = String::new(); 104 let mut buf = String::new();
104 105
105 for child in def.syntax().children() { 106 for child in def.syntax().children() {
106 if child.kind() == SyntaxKind::SEMI { 107 match (child.prev_sibling().map(|c| c.kind()), child.kind()) {
107 buf.push_str(" { unimplemented!() }") 108 (_, SyntaxKind::SEMI) => buf.push_str(" { unimplemented!() }"),
108 } else { 109 (_, SyntaxKind::ATTR) | (_, SyntaxKind::COMMENT) => {}
109 child.text().push_to(&mut buf); 110 (Some(SyntaxKind::ATTR), SyntaxKind::WHITESPACE)
110 } 111 | (Some(SyntaxKind::COMMENT), SyntaxKind::WHITESPACE) => {}
112 _ => child.text().push_to(&mut buf),
113 };
111 } 114 }
112 115
113 buf.trim_end().to_string() 116 buf.trim_end().to_string()
@@ -180,8 +183,7 @@ struct S;
180 183
181impl Foo for S { 184impl Foo for S {
182 fn bar(&self) {} 185 fn bar(&self) {}
183 fn foo(&self) { unimplemented!() } 186 fn foo(&self) { unimplemented!() }<|>
184 fn baz(&self) -> u32 { 42 }<|>
185}", 187}",
186 ); 188 );
187 } 189 }
@@ -193,7 +195,7 @@ impl Foo for S {
193 " 195 "
194trait Foo { fn foo(&self); } 196trait Foo { fn foo(&self); }
195struct S; 197struct S;
196impl Foo for S {<|>}", 198impl Foo for S { <|> }",
197 " 199 "
198trait Foo { fn foo(&self); } 200trait Foo { fn foo(&self); }
199struct S; 201struct S;
@@ -232,8 +234,8 @@ impl Foo for S { <|> }",
232 } 234 }
233 235
234 #[test] 236 #[test]
235 fn test_ignore_unnamed_trait_members() { 237 fn test_ignore_unnamed_trait_members_and_default_methods() {
236 check_assist( 238 check_assist_not_applicable(
237 add_missing_impl_members, 239 add_missing_impl_members,
238 " 240 "
239trait Foo { 241trait Foo {
@@ -242,15 +244,6 @@ trait Foo {
242} 244}
243struct S; 245struct S;
244impl Foo for S { <|> }", 246impl Foo for S { <|> }",
245 "
246trait Foo {
247 fn (arg: u32);
248 fn valid(some: u32) -> bool { false }
249}
250struct S;
251impl Foo for S {
252 fn valid(some: u32) -> bool { false }<|>
253}",
254 ) 247 )
255 } 248 }
256 249
@@ -260,7 +253,7 @@ impl Foo for S {
260 add_missing_impl_members, 253 add_missing_impl_members,
261 " 254 "
262trait Foo { 255trait Foo {
263 fn valid(some: u32) -> bool { false } 256 fn valid(some: u32) -> bool;
264} 257}
265struct S; 258struct S;
266 259
@@ -269,15 +262,42 @@ mod my_mod {
269}", 262}",
270 " 263 "
271trait Foo { 264trait Foo {
272 fn valid(some: u32) -> bool { false } 265 fn valid(some: u32) -> bool;
273} 266}
274struct S; 267struct S;
275 268
276mod my_mod { 269mod my_mod {
277 impl crate::Foo for S { 270 impl crate::Foo for S {
278 fn valid(some: u32) -> bool { false }<|> 271 fn valid(some: u32) -> bool { unimplemented!() }<|>
279 } 272 }
280}", 273}",
281 ) 274 )
282 } 275 }
276
277 #[test]
278 fn test_with_docstring_and_attrs() {
279 check_assist(
280 add_missing_impl_members,
281 r#"
282#[doc(alias = "test alias")]
283trait Foo {
284 /// doc string
285 #[must_use]
286 fn foo(&self);
287}
288struct S;
289impl Foo for S {}<|>"#,
290 r#"
291#[doc(alias = "test alias")]
292trait Foo {
293 /// doc string
294 #[must_use]
295 fn foo(&self);
296}
297struct S;
298impl Foo for S {
299 fn foo(&self) { unimplemented!() }<|>
300}"#,
301 )
302 }
283} 303}