From 4e142757e167ac16ce65ba1c743e131aba83cdc4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 16 May 2021 14:18:49 +0300 Subject: minor: use uniform names --- crates/ide_assists/src/assist_context.rs | 6 +++--- crates/ide_assists/src/handlers/auto_import.rs | 4 ++-- crates/ide_assists/src/handlers/expand_glob_import.rs | 2 +- .../src/handlers/extract_struct_from_enum_variant.rs | 6 +++--- crates/ide_assists/src/handlers/introduce_named_lifetime.rs | 12 ++++++------ crates/ide_assists/src/handlers/merge_imports.rs | 8 ++++---- crates/ide_assists/src/handlers/move_bounds.rs | 4 ++-- crates/ide_assists/src/handlers/pull_assignment_up.rs | 4 ++-- crates/ide_assists/src/handlers/reorder_fields.rs | 4 ++-- crates/ide_assists/src/handlers/reorder_impl.rs | 3 +-- .../src/handlers/replace_impl_trait_with_generic.rs | 4 ++-- .../src/handlers/replace_qualified_name_with_use.rs | 2 +- 12 files changed, 29 insertions(+), 30 deletions(-) diff --git a/crates/ide_assists/src/assist_context.rs b/crates/ide_assists/src/assist_context.rs index 682f0ff5e..20754a02a 100644 --- a/crates/ide_assists/src/assist_context.rs +++ b/crates/ide_assists/src/assist_context.rs @@ -238,8 +238,8 @@ impl AssistBuilder { } } - pub(crate) fn make_ast_mut(&mut self, node: N) -> N { - N::cast(self.make_mut(node.syntax().clone())).unwrap() + pub(crate) fn make_mut(&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) } diff --git a/crates/ide_assists/src/handlers/auto_import.rs b/crates/ide_assists/src/handlers/auto_import.rs index 506cc292c..dda5a6631 100644 --- a/crates/ide_assists/src/handlers/auto_import.rs +++ b/crates/ide_assists/src/handlers/auto_import.rs @@ -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); }, diff --git a/crates/ide_assists/src/handlers/expand_glob_import.rs b/crates/ide_assists/src/handlers/expand_glob_import.rs index da8d245e5..79cb08d69 100644 --- a/crates/ide_assists/src/handlers/expand_glob_import.rs +++ b/crates/ide_assists/src/handlers/expand_glob_import.rs @@ -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| { diff --git a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs index 8e2178391..007aba23d 100644 --- a/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs @@ -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, diff --git a/crates/ide_assists/src/handlers/introduce_named_lifetime.rs b/crates/ide_assists/src/handlers/introduce_named_lifetime.rs index 68bc15120..16f8f9d70 100644 --- a/crates/ide_assists/src/handlers/introduce_named_lifetime.rs +++ b/crates/ide_assists/src/handlers/introduce_named_lifetime.rs @@ -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)), } } diff --git a/crates/ide_assists/src/handlers/merge_imports.rs b/crates/ide_assists/src/handlers/merge_imports.rs index 3cd090737..31854840c 100644 --- a/crates/ide_assists/src/handlers/merge_imports.rs +++ b/crates/ide_assists/src/handlers/merge_imports.rs @@ -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() diff --git a/crates/ide_assists/src/handlers/move_bounds.rs b/crates/ide_assists/src/handlers/move_bounds.rs index fa3f76609..d89d11bdf 100644 --- a/crates/ide_assists/src/handlers/move_bounds.rs +++ b/crates/ide_assists/src/handlers/move_bounds.rs @@ -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 { diff --git a/crates/ide_assists/src/handlers/pull_assignment_up.rs b/crates/ide_assists/src/handlers/pull_assignment_up.rs index 3128faa68..f07b8a6c0 100644 --- a/crates/ide_assists/src/handlers/pull_assignment_up.rs +++ b/crates/ide_assists/src/handlers/pull_assignment_up.rs @@ -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(); diff --git a/crates/ide_assists/src/handlers/reorder_fields.rs b/crates/ide_assists/src/handlers/reorder_fields.rs index e90bbdbcf..933acead1 100644 --- a/crates/ide_assists/src/handlers/reorder_fields.rs +++ b/crates/ide_assists/src/handlers/reorder_fields.rs @@ -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) } }, ) diff --git a/crates/ide_assists/src/handlers/reorder_impl.rs b/crates/ide_assists/src/handlers/reorder_impl.rs index 54a9a468e..5a6a9f158 100644 --- a/crates/ide_assists/src/handlers/reorder_impl.rs +++ b/crates/ide_assists/src/handlers/reorder_impl.rs @@ -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::>(); + let methods = methods.into_iter().map(|fn_| builder.make_mut(fn_)).collect::>(); methods .into_iter() .zip(sorted) diff --git a/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs b/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs index 15420aedf..540a905cc 100644 --- a/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs +++ b/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs @@ -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); diff --git a/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs index 99ba79860..39f5eb4ff 100644 --- a/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs @@ -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); -- cgit v1.2.3