From e0a60e71d7aab59858f62a16fce52ba35aeafc28 Mon Sep 17 00:00:00 2001 From: unexge Date: Wed, 21 Apr 2021 10:57:36 +0300 Subject: Add larger example for "Convert to named struct" assist --- .../convert_tuple_struct_to_named_struct.rs | 34 +++++++++++++++++++--- crates/ide_assists/src/tests/generated.rs | 34 +++++++++++++++++++--- 2 files changed, 60 insertions(+), 8 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 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, // Converts tuple struct to struct with named fields. // // ``` -// struct Inner; -// struct A$0(Inner); +// struct Point$0(f32, f32); +// +// impl Point { +// pub fn new(x: f32, y: f32) -> Self { +// Point(x, y) +// } +// +// pub fn x(&self) -> f32 { +// self.0 +// } +// +// pub fn y(&self) -> f32 { +// self.1 +// } +// } // ``` // -> // ``` -// struct Inner; -// struct A { field1: Inner } +// struct Point { field1: f32, field2: f32 } +// +// impl Point { +// pub fn new(x: f32, y: f32) -> Self { +// Point { field1: x, field2: y } +// } +// +// pub fn x(&self) -> f32 { +// self.field1 +// } +// +// pub fn y(&self) -> f32 { +// self.field2 +// } +// } // ``` pub(crate) fn convert_tuple_struct_to_named_struct( 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() { check_doc_test( "convert_tuple_struct_to_named_struct", r#####" -struct Inner; -struct A$0(Inner); +struct Point$0(f32, f32); + +impl Point { + pub fn new(x: f32, y: f32) -> Self { + Point(x, y) + } + + pub fn x(&self) -> f32 { + self.0 + } + + pub fn y(&self) -> f32 { + self.1 + } +} "#####, r#####" -struct Inner; -struct A { field1: Inner } +struct Point { field1: f32, field2: f32 } + +impl Point { + pub fn new(x: f32, y: f32) -> Self { + Point { field1: x, field2: y } + } + + pub fn x(&self) -> f32 { + self.field1 + } + + pub fn y(&self) -> f32 { + self.field2 + } +} "#####, ) } -- cgit v1.2.3