aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers
diff options
context:
space:
mode:
authorMikhail Rakhmanov <[email protected]>2020-05-23 00:41:08 +0100
committerMikhail Rakhmanov <[email protected]>2020-05-23 00:41:08 +0100
commit6ee1c60c9cff781e10d6379f68fc951378403f6b (patch)
tree941d45aed0effe537c4a0742523f074b53e1a6db /crates/ra_assists/src/handlers
parent4984520ef565e926ba08c6512715ed631e4527e4 (diff)
Further review fixes
Diffstat (limited to 'crates/ra_assists/src/handlers')
-rw-r--r--crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs20
1 files changed, 9 insertions, 11 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 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 {