aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/Cargo.toml1
-rw-r--r--crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs20
2 files changed, 9 insertions, 12 deletions
diff --git a/crates/ra_assists/Cargo.toml b/crates/ra_assists/Cargo.toml
index f3481bdeb..3bcf58ba4 100644
--- a/crates/ra_assists/Cargo.toml
+++ b/crates/ra_assists/Cargo.toml
@@ -20,6 +20,5 @@ ra_fmt = { path = "../ra_fmt" }
20ra_prof = { path = "../ra_prof" } 20ra_prof = { path = "../ra_prof" }
21ra_db = { path = "../ra_db" } 21ra_db = { path = "../ra_db" }
22ra_ide_db = { path = "../ra_ide_db" } 22ra_ide_db = { path = "../ra_ide_db" }
23hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" }
24hir = { path = "../ra_hir", package = "ra_hir" } 23hir = { path = "../ra_hir", package = "ra_hir" }
25test_utils = { path = "../test_utils" } 24test_utils = { path = "../test_utils" }
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 3250eed5b..359283802 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
@@ -1,4 +1,3 @@
1use hir_expand::name::AsName;
2use ra_ide_db::{ 1use ra_ide_db::{
3 defs::Definition, imports_locator::ImportsLocator, search::Reference, RootDatabase, 2 defs::Definition, imports_locator::ImportsLocator, search::Reference, RootDatabase,
4}; 3};
@@ -15,14 +14,14 @@ use crate::{
15 AssistContext, AssistId, Assists, 14 AssistContext, AssistId, Assists,
16}; 15};
17use ast::{ArgListOwner, VisibilityOwner}; 16use ast::{ArgListOwner, VisibilityOwner};
18use hir::{EnumVariant, Module, ModuleDef}; 17use hir::{AsName, EnumVariant, Module, ModuleDef};
19use ra_db::FileId; 18use ra_db::FileId;
20use ra_fmt::leading_indent; 19use ra_fmt::leading_indent;
21use rustc_hash::FxHashSet; 20use rustc_hash::FxHashSet;
22 21
23// Assist extract_struct_from_enum 22// Assist extract_struct_from_enum
24// 23//
25// Extracts a from struct from enum variant 24// Extracts a struct from enum variant
26// 25//
27// ``` 26// ```
28// enum A { <|>One(u32, u32) } 27// enum A { <|>One(u32, u32) }
@@ -41,7 +40,7 @@ pub(crate) fn extract_struct_from_enum(acc: &mut Assists, ctx: &AssistContext) -
41 }; 40 };
42 let variant_name = variant.name()?.to_string(); 41 let variant_name = variant.name()?.to_string();
43 let enum_ast = variant.parent_enum(); 42 let enum_ast = variant.parent_enum();
44 let enum_name = enum_ast.name().unwrap().to_string(); 43 let enum_name = enum_ast.name()?.to_string();
45 let visibility = enum_ast.visibility(); 44 let visibility = enum_ast.visibility();
46 let variant_hir = ctx.sema.to_def(&variant)?; 45 let variant_hir = ctx.sema.to_def(&variant)?;
47 46
@@ -88,13 +87,12 @@ pub(crate) fn extract_struct_from_enum(acc: &mut Assists, ctx: &AssistContext) -
88} 87}
89 88
90fn existing_struct_def(db: &RootDatabase, variant_name: &str, variant: &EnumVariant) -> bool { 89fn existing_struct_def(db: &RootDatabase, variant_name: &str, variant: &EnumVariant) -> bool {
91 let module_defs = variant.parent_enum(db).module(db).scope(db, None); 90 variant
92 for (name, _) in module_defs { 91 .parent_enum(db)
93 if name.to_string() == variant_name.to_string() { 92 .module(db)
94 return true; 93 .scope(db, None)
95 } 94 .into_iter()
96 } 95 .any(|(name, _)| name.to_string() == variant_name.to_string())
97 false
98} 96}
99 97
100fn mod_def_for_target_module(ctx: &AssistContext, enum_name: &str) -> ModuleDef { 98fn mod_def_for_target_module(ctx: &AssistContext, enum_name: &str) -> ModuleDef {