use rustc_hash::FxHashSet;
use syntax::{
ast::{
- self, edit::IndentLevel, edit_in_place::Indent, make, AstNode, AttrsOwner,
- GenericParamsOwner, NameOwner, TypeBoundsOwner, VisibilityOwner,
+ self, edit::IndentLevel, edit_in_place::Indent, make, AstNode, HasAttrs, HasGenericParams,
+ HasName, HasTypeBounds, HasVisibility,
},
match_ast,
ted::{self, Position},
|builder| {
let variant_hir_name = variant_hir.name(ctx.db());
let enum_module_def = ModuleDef::from(enum_hir);
- let usages =
- Definition::ModuleDef(ModuleDef::Variant(variant_hir)).usages(&ctx.sema).all();
+ let usages = Definition::Variant(variant_hir).usages(&ctx.sema).all();
let mut visited_modules_set = FxHashSet::default();
let current_module = enum_hir.module(ctx.db());
// record file references of the file the def resides in, we only want to swap to the edited file in the builder once
let mut def_file_references = None;
for (file_id, references) in usages {
- if file_id == ctx.frange.file_id {
+ if file_id == ctx.file_id() {
def_file_references = Some(references);
continue;
}
apply_references(ctx.config.insert_use, path, node, import)
});
}
- builder.edit_file(ctx.frange.file_id);
+ builder.edit_file(ctx.file_id());
let variant = builder.make_mut(variant.clone());
if let Some(references) = def_file_references {
let variant_attrs = attrs_and_docs(variant.syntax())
.map(|tok| match tok.kind() {
WHITESPACE => make::tokens::single_newline().into(),
- _ => tok.into(),
+ _ => tok,
})
.collect();
ted::insert_all(Position::first_child_of(strukt.syntax()), variant_attrs);
Some(gpl) => {
let gpl = gpl.clone_for_update();
gpl.generic_params().for_each(|gp| {
- match gp {
+ let tbl = match gp {
ast::GenericParam::LifetimeParam(it) => it.type_bound_list(),
ast::GenericParam::TypeParam(it) => it.type_bound_list(),
ast::GenericParam::ConstParam(_) => return,
+ };
+ if let Some(tbl) = tbl {
+ tbl.remove();
}
- .map(|it| it.remove());
});
make::ty(&format!("{}<{}>", name.text(), gpl.generic_params().join(", ")))
}
if let Some(mut mod_path) = mod_path {
mod_path.pop_segment();
mod_path.push_segment(variant_hir_name.clone());
- let scope = ImportScope::find_insert_use_container(&scope_node)?;
+ let scope = ImportScope::find_insert_use_container(&scope_node, &ctx.sema)?;
visited_modules.insert(module);
return Some((segment, scope_node, Some((scope, mod_path))));
}