From 97270dfb9162bfcefa78a7ed39551069ae267f48 Mon Sep 17 00:00:00 2001 From: unexge Date: Fri, 23 Apr 2021 13:08:07 +0300 Subject: Stop iterating reference after made an edit in "Convert to named struct" assist --- .../convert_tuple_struct_to_named_struct.rs | 49 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs b/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs index 994e1a01a..cac4bec3d 100644 --- a/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs +++ b/crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs @@ -160,7 +160,7 @@ fn edit_struct_references( .to_string(), ); }, - _ => () + _ => return None, } } Some(()) @@ -170,7 +170,9 @@ fn edit_struct_references( edit.edit_file(file_id); for r in refs { for node in r.name.syntax().ancestors() { - edit_node(edit, node); + if edit_node(edit, node).is_some() { + break; + } } } } @@ -377,6 +379,49 @@ impl A { ); } + #[test] + fn convert_struct_with_wrapped_references() { + check_assist( + convert_tuple_struct_to_named_struct, + r#" +struct Inner$0(u32); +struct Outer(Inner); + +impl Outer { + fn new() -> Self { + Self(Inner(42)) + } + + fn into_inner(self) -> u32 { + (self.0).0 + } + + fn into_inner_destructed(self) -> u32 { + let Outer(Inner(x)) = self; + x + } +}"#, + r#" +struct Inner { field1: u32 } +struct Outer(Inner); + +impl Outer { + fn new() -> Self { + Self(Inner { field1: 42 }) + } + + fn into_inner(self) -> u32 { + (self.0).field1 + } + + fn into_inner_destructed(self) -> u32 { + let Outer(Inner { field1: x }) = self; + x + } +}"#, + ); + } + #[test] fn convert_struct_with_multi_file_references() { check_assist( -- cgit v1.2.3