diff options
Diffstat (limited to 'crates/ide_assists')
-rw-r--r-- | crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs | 34 | ||||
-rw-r--r-- | crates/ide_assists/src/tests/generated.rs | 34 |
2 files changed, 60 insertions, 8 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 b68b1d06f..ee6ddfbc6 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 | |||
@@ -12,13 +12,39 @@ use crate::{assist_context::AssistBuilder, AssistContext, AssistId, AssistKind, | |||
12 | // Converts tuple struct to struct with named fields. | 12 | // Converts tuple struct to struct with named fields. |
13 | // | 13 | // |
14 | // ``` | 14 | // ``` |
15 | // struct Inner; | 15 | // struct Point$0(f32, f32); |
16 | // struct A$0(Inner); | 16 | // |
17 | // impl Point { | ||
18 | // pub fn new(x: f32, y: f32) -> Self { | ||
19 | // Point(x, y) | ||
20 | // } | ||
21 | // | ||
22 | // pub fn x(&self) -> f32 { | ||
23 | // self.0 | ||
24 | // } | ||
25 | // | ||
26 | // pub fn y(&self) -> f32 { | ||
27 | // self.1 | ||
28 | // } | ||
29 | // } | ||
17 | // ``` | 30 | // ``` |
18 | // -> | 31 | // -> |
19 | // ``` | 32 | // ``` |
20 | // struct Inner; | 33 | // struct Point { field1: f32, field2: f32 } |
21 | // struct A { field1: Inner } | 34 | // |
35 | // impl Point { | ||
36 | // pub fn new(x: f32, y: f32) -> Self { | ||
37 | // Point { field1: x, field2: y } | ||
38 | // } | ||
39 | // | ||
40 | // pub fn x(&self) -> f32 { | ||
41 | // self.field1 | ||
42 | // } | ||
43 | // | ||
44 | // pub fn y(&self) -> f32 { | ||
45 | // self.field2 | ||
46 | // } | ||
47 | // } | ||
22 | // ``` | 48 | // ``` |
23 | pub(crate) fn convert_tuple_struct_to_named_struct( | 49 | pub(crate) fn convert_tuple_struct_to_named_struct( |
24 | acc: &mut Assists, | 50 | acc: &mut Assists, |
diff --git a/crates/ide_assists/src/tests/generated.rs b/crates/ide_assists/src/tests/generated.rs index 53f455adf..f4a4749c8 100644 --- a/crates/ide_assists/src/tests/generated.rs +++ b/crates/ide_assists/src/tests/generated.rs | |||
@@ -296,12 +296,38 @@ fn doctest_convert_tuple_struct_to_named_struct() { | |||
296 | check_doc_test( | 296 | check_doc_test( |
297 | "convert_tuple_struct_to_named_struct", | 297 | "convert_tuple_struct_to_named_struct", |
298 | r#####" | 298 | r#####" |
299 | struct Inner; | 299 | struct Point$0(f32, f32); |
300 | struct A$0(Inner); | 300 | |
301 | impl Point { | ||
302 | pub fn new(x: f32, y: f32) -> Self { | ||
303 | Point(x, y) | ||
304 | } | ||
305 | |||
306 | pub fn x(&self) -> f32 { | ||
307 | self.0 | ||
308 | } | ||
309 | |||
310 | pub fn y(&self) -> f32 { | ||
311 | self.1 | ||
312 | } | ||
313 | } | ||
301 | "#####, | 314 | "#####, |
302 | r#####" | 315 | r#####" |
303 | struct Inner; | 316 | struct Point { field1: f32, field2: f32 } |
304 | struct A { field1: Inner } | 317 | |
318 | impl Point { | ||
319 | pub fn new(x: f32, y: f32) -> Self { | ||
320 | Point { field1: x, field2: y } | ||
321 | } | ||
322 | |||
323 | pub fn x(&self) -> f32 { | ||
324 | self.field1 | ||
325 | } | ||
326 | |||
327 | pub fn y(&self) -> f32 { | ||
328 | self.field2 | ||
329 | } | ||
330 | } | ||
305 | "#####, | 331 | "#####, |
306 | ) | 332 | ) |
307 | } | 333 | } |