minor: use uniform names

This commit is contained in:
Aleksey Kladov 2021-05-16 14:18:49 +03:00
parent a57bd59f35
commit 4e142757e1
12 changed files with 29 additions and 30 deletions

View File

@ -238,8 +238,8 @@ impl AssistBuilder {
}
}
pub(crate) fn make_ast_mut<N: AstNode>(&mut self, node: N) -> N {
N::cast(self.make_mut(node.syntax().clone())).unwrap()
pub(crate) fn make_mut<N: AstNode>(&mut self, node: N) -> N {
self.mutated_tree.get_or_insert_with(|| TreeMutator::new(node.syntax())).make_mut(&node)
}
/// Returns a copy of the `node`, suitable for mutation.
///
@ -251,7 +251,7 @@ impl AssistBuilder {
/// The typical pattern for an assist is to find specific nodes in the read
/// phase, and then get their mutable couterparts using `make_mut` in the
/// mutable state.
pub(crate) fn make_mut(&mut self, node: SyntaxNode) -> SyntaxNode {
pub(crate) fn make_syntax_mut(&mut self, node: SyntaxNode) -> SyntaxNode {
self.mutated_tree.get_or_insert_with(|| TreeMutator::new(&node)).make_syntax_mut(&node)
}

View File

@ -102,8 +102,8 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
range,
|builder| {
let scope = match scope.clone() {
ImportScope::File(it) => ImportScope::File(builder.make_ast_mut(it)),
ImportScope::Module(it) => ImportScope::Module(builder.make_ast_mut(it)),
ImportScope::File(it) => ImportScope::File(builder.make_mut(it)),
ImportScope::Module(it) => ImportScope::Module(builder.make_mut(it)),
};
insert_use(&scope, mod_path_to_ast(&import.import_path), ctx.config.insert_use);
},

View File

@ -61,7 +61,7 @@ pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext) -> Opti
"Expand glob import",
target.text_range(),
|builder| {
let use_tree = builder.make_ast_mut(use_tree);
let use_tree = builder.make_mut(use_tree);
let names_to_import = find_names_to_import(ctx, refs_in_target, imported_defs);
let expanded = make::use_tree_list(names_to_import.iter().map(|n| {

View File

@ -70,7 +70,7 @@ pub(crate) fn extract_struct_from_enum_variant(
continue;
}
builder.edit_file(file_id);
let source_file = builder.make_ast_mut(ctx.sema.parse(file_id));
let source_file = builder.make_mut(ctx.sema.parse(file_id));
let processed = process_references(
ctx,
&mut visited_modules_set,
@ -84,8 +84,8 @@ pub(crate) fn extract_struct_from_enum_variant(
});
}
builder.edit_file(ctx.frange.file_id);
let source_file = builder.make_ast_mut(ctx.sema.parse(ctx.frange.file_id));
let variant = builder.make_ast_mut(variant.clone());
let source_file = builder.make_mut(ctx.sema.parse(ctx.frange.file_id));
let variant = builder.make_mut(variant.clone());
if let Some(references) = def_file_references {
let processed = process_references(
ctx,

View File

@ -84,8 +84,8 @@ fn generate_fn_def_assist(
}
};
acc.add(AssistId(ASSIST_NAME, AssistKind::Refactor), ASSIST_LABEL, lifetime_loc, |builder| {
let fn_def = builder.make_ast_mut(fn_def);
let lifetime = builder.make_ast_mut(lifetime);
let fn_def = builder.make_mut(fn_def);
let lifetime = builder.make_mut(lifetime);
let loc_needing_lifetime =
loc_needing_lifetime.and_then(|it| it.make_mut(builder).to_position());
@ -107,8 +107,8 @@ fn generate_impl_def_assist(
) -> Option<()> {
let new_lifetime_param = generate_unique_lifetime_param_name(impl_def.generic_param_list())?;
acc.add(AssistId(ASSIST_NAME, AssistKind::Refactor), ASSIST_LABEL, lifetime_loc, |builder| {
let impl_def = builder.make_ast_mut(impl_def);
let lifetime = builder.make_ast_mut(lifetime);
let impl_def = builder.make_mut(impl_def);
let lifetime = builder.make_mut(lifetime);
impl_def.get_or_create_generic_param_list().add_generic_param(
make::lifetime_param(new_lifetime_param.clone()).clone_for_update().into(),
@ -141,8 +141,8 @@ enum NeedsLifetime {
impl NeedsLifetime {
fn make_mut(self, builder: &mut AssistBuilder) -> Self {
match self {
Self::SelfParam(it) => Self::SelfParam(builder.make_ast_mut(it)),
Self::RefType(it) => Self::RefType(builder.make_ast_mut(it)),
Self::SelfParam(it) => Self::SelfParam(builder.make_mut(it)),
Self::RefType(it) => Self::RefType(builder.make_mut(it)),
}
}

View File

@ -47,16 +47,16 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<()
target,
|builder| {
if let Some((to_replace, replacement, to_remove)) = imports {
let to_replace = builder.make_ast_mut(to_replace);
let to_remove = builder.make_ast_mut(to_remove);
let to_replace = builder.make_mut(to_replace);
let to_remove = builder.make_mut(to_remove);
ted::replace(to_replace.syntax(), replacement.syntax());
to_remove.remove();
}
if let Some((to_replace, replacement, to_remove)) = uses {
let to_replace = builder.make_ast_mut(to_replace);
let to_remove = builder.make_ast_mut(to_remove);
let to_replace = builder.make_mut(to_replace);
let to_remove = builder.make_mut(to_remove);
ted::replace(to_replace.syntax(), replacement.syntax());
to_remove.remove()

View File

@ -36,8 +36,8 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext
"Move to where clause",
target,
|edit| {
let type_param_list = edit.make_ast_mut(type_param_list);
let parent = edit.make_mut(parent);
let type_param_list = edit.make_mut(type_param_list);
let parent = edit.make_syntax_mut(parent);
let where_clause: ast::WhereClause = match_ast! {
match parent {

View File

@ -74,10 +74,10 @@ pub(crate) fn pull_assignment_up(acc: &mut Assists, ctx: &AssistContext) -> Opti
let assignments: Vec<_> = collector
.assignments
.into_iter()
.map(|(stmt, rhs)| (edit.make_ast_mut(stmt), rhs.clone_for_update()))
.map(|(stmt, rhs)| (edit.make_mut(stmt), rhs.clone_for_update()))
.collect();
let tgt = edit.make_ast_mut(tgt);
let tgt = edit.make_mut(tgt);
for (stmt, rhs) in assignments {
let mut stmt = stmt.syntax().clone();

View File

@ -70,10 +70,10 @@ pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext) -> Option<(
target,
|builder| match fields {
Either::Left((sorted, field_list)) => {
replace(builder.make_ast_mut(field_list).fields(), sorted)
replace(builder.make_mut(field_list).fields(), sorted)
}
Either::Right((sorted, field_list)) => {
replace(builder.make_ast_mut(field_list).fields(), sorted)
replace(builder.make_mut(field_list).fields(), sorted)
}
},
)

View File

@ -79,8 +79,7 @@ pub(crate) fn reorder_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
"Sort methods",
target,
|builder| {
let methods =
methods.into_iter().map(|fn_| builder.make_ast_mut(fn_)).collect::<Vec<_>>();
let methods = methods.into_iter().map(|fn_| builder.make_mut(fn_)).collect::<Vec<_>>();
methods
.into_iter()
.zip(sorted)

View File

@ -32,8 +32,8 @@ pub(crate) fn replace_impl_trait_with_generic(
"Replace impl trait with generic",
target,
|edit| {
let impl_trait_type = edit.make_ast_mut(impl_trait_type);
let fn_ = edit.make_ast_mut(fn_);
let impl_trait_type = edit.make_mut(impl_trait_type);
let fn_ = edit.make_mut(fn_);
let type_param_name = suggest_name::for_generic_parameter(&impl_trait_type);

View File

@ -40,7 +40,7 @@ pub(crate) fn replace_qualified_name_with_use(
|builder| {
// Now that we've brought the name into scope, re-qualify all paths that could be
// affected (that is, all paths inside the node we added the `use` to).
let syntax = builder.make_mut(syntax.clone());
let syntax = builder.make_syntax_mut(syntax.clone());
if let Some(ref import_scope) = ImportScope::from(syntax.clone()) {
shorten_paths(&syntax, &path.clone_for_update());
insert_use(import_scope, path, ctx.config.insert_use);