Skip to content

Commit e0a60e7

Browse files
committed
Add larger example for "Convert to named struct" assist
1 parent 53599d1 commit e0a60e7

File tree

2 files changed

+60
-8
lines changed

2 files changed

+60
-8
lines changed

crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,39 @@ use crate::{assist_context::AssistBuilder, AssistContext, AssistId, AssistKind,
1212
// Converts tuple struct to struct with named fields.
1313
//
1414
// ```
15-
// struct Inner;
16-
// struct A$0(Inner);
15+
// struct Point$0(f32, f32);
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+
// }
1730
// ```
1831
// ->
1932
// ```
20-
// struct Inner;
21-
// struct A { field1: Inner }
33+
// struct Point { field1: f32, field2: f32 }
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+
// }
2248
// ```
2349
pub(crate) fn convert_tuple_struct_to_named_struct(
2450
acc: &mut Assists,

crates/ide_assists/src/tests/generated.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,38 @@ fn doctest_convert_tuple_struct_to_named_struct() {
296296
check_doc_test(
297297
"convert_tuple_struct_to_named_struct",
298298
r#####"
299-
struct Inner;
300-
struct A$0(Inner);
299+
struct Point$0(f32, f32);
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+
}
301314
"#####,
302315
r#####"
303-
struct Inner;
304-
struct A { field1: Inner }
316+
struct Point { field1: f32, field2: f32 }
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+
}
305331
"#####,
306332
)
307333
}

0 commit comments

Comments
 (0)