diff options
author | unexge <[email protected]> | 2021-04-23 11:08:07 +0100 |
---|---|---|
committer | unexge <[email protected]> | 2021-04-23 11:08:07 +0100 |
commit | 97270dfb9162bfcefa78a7ed39551069ae267f48 (patch) | |
tree | 5157590f7bc69cf2eb5eb9ddad54b493e80d01c9 /crates/ide_assists | |
parent | affd8d351863a4f9f5729eb3487942fa7bfa5755 (diff) |
Stop iterating reference after made an edit in "Convert to named struct" assist
Diffstat (limited to 'crates/ide_assists')
-rw-r--r-- | crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs | 49 |
1 files changed, 47 insertions, 2 deletions
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( | |||
160 | .to_string(), | 160 | .to_string(), |
161 | ); | 161 | ); |
162 | }, | 162 | }, |
163 | _ => () | 163 | _ => return None, |
164 | } | 164 | } |
165 | } | 165 | } |
166 | Some(()) | 166 | Some(()) |
@@ -170,7 +170,9 @@ fn edit_struct_references( | |||
170 | edit.edit_file(file_id); | 170 | edit.edit_file(file_id); |
171 | for r in refs { | 171 | for r in refs { |
172 | for node in r.name.syntax().ancestors() { | 172 | for node in r.name.syntax().ancestors() { |
173 | edit_node(edit, node); | 173 | if edit_node(edit, node).is_some() { |
174 | break; | ||
175 | } | ||
174 | } | 176 | } |
175 | } | 177 | } |
176 | } | 178 | } |
@@ -378,6 +380,49 @@ impl A { | |||
378 | } | 380 | } |
379 | 381 | ||
380 | #[test] | 382 | #[test] |
383 | fn convert_struct_with_wrapped_references() { | ||
384 | check_assist( | ||
385 | convert_tuple_struct_to_named_struct, | ||
386 | r#" | ||
387 | struct Inner$0(u32); | ||
388 | struct Outer(Inner); | ||
389 | |||
390 | impl Outer { | ||
391 | fn new() -> Self { | ||
392 | Self(Inner(42)) | ||
393 | } | ||
394 | |||
395 | fn into_inner(self) -> u32 { | ||
396 | (self.0).0 | ||
397 | } | ||
398 | |||
399 | fn into_inner_destructed(self) -> u32 { | ||
400 | let Outer(Inner(x)) = self; | ||
401 | x | ||
402 | } | ||
403 | }"#, | ||
404 | r#" | ||
405 | struct Inner { field1: u32 } | ||
406 | struct Outer(Inner); | ||
407 | |||
408 | impl Outer { | ||
409 | fn new() -> Self { | ||
410 | Self(Inner { field1: 42 }) | ||
411 | } | ||
412 | |||
413 | fn into_inner(self) -> u32 { | ||
414 | (self.0).field1 | ||
415 | } | ||
416 | |||
417 | fn into_inner_destructed(self) -> u32 { | ||
418 | let Outer(Inner { field1: x }) = self; | ||
419 | x | ||
420 | } | ||
421 | }"#, | ||
422 | ); | ||
423 | } | ||
424 | |||
425 | #[test] | ||
381 | fn convert_struct_with_multi_file_references() { | 426 | fn convert_struct_with_multi_file_references() { |
382 | check_assist( | 427 | check_assist( |
383 | convert_tuple_struct_to_named_struct, | 428 | convert_tuple_struct_to_named_struct, |