Further review fixes

This commit is contained in:
Mikhail Rakhmanov 2020-05-23 01:41:08 +02:00
parent 4984520ef5
commit 6ee1c60c9c
4 changed files with 12 additions and 15 deletions

1
Cargo.lock generated
View file

@ -921,7 +921,6 @@ dependencies = [
"ra_db", "ra_db",
"ra_fmt", "ra_fmt",
"ra_hir", "ra_hir",
"ra_hir_expand",
"ra_ide_db", "ra_ide_db",
"ra_prof", "ra_prof",
"ra_syntax", "ra_syntax",

View file

@ -20,6 +20,5 @@ ra_fmt = { path = "../ra_fmt" }
ra_prof = { path = "../ra_prof" } ra_prof = { path = "../ra_prof" }
ra_db = { path = "../ra_db" } ra_db = { path = "../ra_db" }
ra_ide_db = { path = "../ra_ide_db" } ra_ide_db = { path = "../ra_ide_db" }
hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" }
hir = { path = "../ra_hir", package = "ra_hir" } hir = { path = "../ra_hir", package = "ra_hir" }
test_utils = { path = "../test_utils" } test_utils = { path = "../test_utils" }

View file

@ -1,4 +1,3 @@
use hir_expand::name::AsName;
use ra_ide_db::{ use ra_ide_db::{
defs::Definition, imports_locator::ImportsLocator, search::Reference, RootDatabase, defs::Definition, imports_locator::ImportsLocator, search::Reference, RootDatabase,
}; };
@ -15,14 +14,14 @@ use crate::{
AssistContext, AssistId, Assists, AssistContext, AssistId, Assists,
}; };
use ast::{ArgListOwner, VisibilityOwner}; use ast::{ArgListOwner, VisibilityOwner};
use hir::{EnumVariant, Module, ModuleDef}; use hir::{AsName, EnumVariant, Module, ModuleDef};
use ra_db::FileId; use ra_db::FileId;
use ra_fmt::leading_indent; use ra_fmt::leading_indent;
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
// Assist extract_struct_from_enum // Assist extract_struct_from_enum
// //
// Extracts a from struct from enum variant // Extracts a struct from enum variant
// //
// ``` // ```
// enum A { <|>One(u32, u32) } // enum A { <|>One(u32, u32) }
@ -41,7 +40,7 @@ pub(crate) fn extract_struct_from_enum(acc: &mut Assists, ctx: &AssistContext) -
}; };
let variant_name = variant.name()?.to_string(); let variant_name = variant.name()?.to_string();
let enum_ast = variant.parent_enum(); let enum_ast = variant.parent_enum();
let enum_name = enum_ast.name().unwrap().to_string(); let enum_name = enum_ast.name()?.to_string();
let visibility = enum_ast.visibility(); let visibility = enum_ast.visibility();
let variant_hir = ctx.sema.to_def(&variant)?; let variant_hir = ctx.sema.to_def(&variant)?;
@ -88,13 +87,12 @@ pub(crate) fn extract_struct_from_enum(acc: &mut Assists, ctx: &AssistContext) -
} }
fn existing_struct_def(db: &RootDatabase, variant_name: &str, variant: &EnumVariant) -> bool { fn existing_struct_def(db: &RootDatabase, variant_name: &str, variant: &EnumVariant) -> bool {
let module_defs = variant.parent_enum(db).module(db).scope(db, None); variant
for (name, _) in module_defs { .parent_enum(db)
if name.to_string() == variant_name.to_string() { .module(db)
return true; .scope(db, None)
} .into_iter()
} .any(|(name, _)| name.to_string() == variant_name.to_string())
false
} }
fn mod_def_for_target_module(ctx: &AssistContext, enum_name: &str) -> ModuleDef { fn mod_def_for_target_module(ctx: &AssistContext, enum_name: &str) -> ModuleDef {

View file

@ -70,7 +70,8 @@ pub use hir_def::{
type_ref::Mutability, type_ref::Mutability,
}; };
pub use hir_expand::{ pub use hir_expand::{
hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, hygiene::Hygiene,
MacroFile, Origin, name::{AsName, Name},
HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin,
}; };
pub use hir_ty::{display::HirDisplay, CallableDef}; pub use hir_ty::{display::HirDisplay, CallableDef};