aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs21
-rw-r--r--crates/ra_assists/src/lib.rs2
-rw-r--r--crates/ra_assists/src/tests/generated.rs15
3 files changed, 28 insertions, 10 deletions
diff --git a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs
index a36587633..2b1951aff 100644
--- a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs
+++ b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs
@@ -18,9 +18,9 @@ use ra_db::FileId;
18use ra_fmt::leading_indent; 18use ra_fmt::leading_indent;
19use rustc_hash::FxHashSet; 19use rustc_hash::FxHashSet;
20 20
21// Assist extract_struct_from_enum 21// Assist: extract_struct_from_enum_variant
22// 22//
23// Extracts a struct from enum variant 23// Extracts a struct from enum variant.
24// 24//
25// ``` 25// ```
26// enum A { <|>One(u32, u32) } 26// enum A { <|>One(u32, u32) }
@@ -29,9 +29,12 @@ use rustc_hash::FxHashSet;
29// ``` 29// ```
30// struct One(pub u32, pub u32); 30// struct One(pub u32, pub u32);
31// 31//
32// enum A { One(One) }" 32// enum A { One(One) }
33// ``` 33// ```
34pub(crate) fn extract_struct_from_enum(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 34pub(crate) fn extract_struct_from_enum_variant(
35 acc: &mut Assists,
36 ctx: &AssistContext,
37) -> Option<()> {
35 let variant = ctx.find_node_at_offset::<ast::EnumVariant>()?; 38 let variant = ctx.find_node_at_offset::<ast::EnumVariant>()?;
36 let field_list = match variant.kind() { 39 let field_list = match variant.kind() {
37 ast::StructKind::Tuple(field_list) => field_list, 40 ast::StructKind::Tuple(field_list) => field_list,
@@ -221,7 +224,7 @@ mod tests {
221 #[test] 224 #[test]
222 fn test_extract_struct_several_fields() { 225 fn test_extract_struct_several_fields() {
223 check_assist( 226 check_assist(
224 extract_struct_from_enum, 227 extract_struct_from_enum_variant,
225 "enum A { <|>One(u32, u32) }", 228 "enum A { <|>One(u32, u32) }",
226 r#"struct One(pub u32, pub u32); 229 r#"struct One(pub u32, pub u32);
227 230
@@ -232,7 +235,7 @@ enum A { One(One) }"#,
232 #[test] 235 #[test]
233 fn test_extract_struct_one_field() { 236 fn test_extract_struct_one_field() {
234 check_assist( 237 check_assist(
235 extract_struct_from_enum, 238 extract_struct_from_enum_variant,
236 "enum A { <|>One(u32) }", 239 "enum A { <|>One(u32) }",
237 r#"struct One(pub u32); 240 r#"struct One(pub u32);
238 241
@@ -243,7 +246,7 @@ enum A { One(One) }"#,
243 #[test] 246 #[test]
244 fn test_extract_struct_pub_visibility() { 247 fn test_extract_struct_pub_visibility() {
245 check_assist( 248 check_assist(
246 extract_struct_from_enum, 249 extract_struct_from_enum_variant,
247 "pub enum A { <|>One(u32, u32) }", 250 "pub enum A { <|>One(u32, u32) }",
248 r#"pub struct One(pub u32, pub u32); 251 r#"pub struct One(pub u32, pub u32);
249 252
@@ -254,7 +257,7 @@ pub enum A { One(One) }"#,
254 #[test] 257 #[test]
255 fn test_extract_struct_with_complex_imports() { 258 fn test_extract_struct_with_complex_imports() {
256 check_assist( 259 check_assist(
257 extract_struct_from_enum, 260 extract_struct_from_enum_variant,
258 r#"mod my_mod { 261 r#"mod my_mod {
259 fn another_fn() { 262 fn another_fn() {
260 let m = my_other_mod::MyEnum::MyField(1, 1); 263 let m = my_other_mod::MyEnum::MyField(1, 1);
@@ -305,7 +308,7 @@ fn another_fn() {
305 fn check_not_applicable(ra_fixture: &str) { 308 fn check_not_applicable(ra_fixture: &str) {
306 let fixture = 309 let fixture =
307 format!("//- main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE); 310 format!("//- main.rs crate:main deps:core\n{}\n{}", ra_fixture, FamousDefs::FIXTURE);
308 check_assist_not_applicable(extract_struct_from_enum, &fixture) 311 check_assist_not_applicable(extract_struct_from_enum_variant, &fixture)
309 } 312 }
310 313
311 #[test] 314 #[test]
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index 88ce9b62e..185428bd5 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -156,7 +156,7 @@ mod handlers {
156 change_return_type_to_result::change_return_type_to_result, 156 change_return_type_to_result::change_return_type_to_result,
157 change_visibility::change_visibility, 157 change_visibility::change_visibility,
158 early_return::convert_to_guarded_return, 158 early_return::convert_to_guarded_return,
159 extract_struct_from_enum_variant::extract_struct_from_enum, 159 extract_struct_from_enum_variant::extract_struct_from_enum_variant,
160 fill_match_arms::fill_match_arms, 160 fill_match_arms::fill_match_arms,
161 fix_visibility::fix_visibility, 161 fix_visibility::fix_visibility,
162 flip_binexpr::flip_binexpr, 162 flip_binexpr::flip_binexpr,
diff --git a/crates/ra_assists/src/tests/generated.rs b/crates/ra_assists/src/tests/generated.rs
index d17504529..40a223727 100644
--- a/crates/ra_assists/src/tests/generated.rs
+++ b/crates/ra_assists/src/tests/generated.rs
@@ -338,6 +338,21 @@ fn main() {
338} 338}
339 339
340#[test] 340#[test]
341fn doctest_extract_struct_from_enum_variant() {
342 check_doc_test(
343 "extract_struct_from_enum_variant",
344 r#####"
345enum A { <|>One(u32, u32) }
346"#####,
347 r#####"
348struct One(pub u32, pub u32);
349
350enum A { One(One) }
351"#####,
352 )
353}
354
355#[test]
341fn doctest_fill_match_arms() { 356fn doctest_fill_match_arms() {
342 check_doc_test( 357 check_doc_test(
343 "fill_match_arms", 358 "fill_match_arms",