Skip to content

Commit 4e14275

Browse files
committed
minor: use uniform names
1 parent a57bd59 commit 4e14275

12 files changed

+29
-30
lines changed

crates/ide_assists/src/assist_context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ impl AssistBuilder {
238238
}
239239
}
240240

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

crates/ide_assists/src/handlers/auto_import.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
102102
range,
103103
|builder| {
104104
let scope = match scope.clone() {
105-
ImportScope::File(it) => ImportScope::File(builder.make_ast_mut(it)),
106-
ImportScope::Module(it) => ImportScope::Module(builder.make_ast_mut(it)),
105+
ImportScope::File(it) => ImportScope::File(builder.make_mut(it)),
106+
ImportScope::Module(it) => ImportScope::Module(builder.make_mut(it)),
107107
};
108108
insert_use(&scope, mod_path_to_ast(&import.import_path), ctx.config.insert_use);
109109
},

crates/ide_assists/src/handlers/expand_glob_import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(crate) fn expand_glob_import(acc: &mut Assists, ctx: &AssistContext) -> Opti
6161
"Expand glob import",
6262
target.text_range(),
6363
|builder| {
64-
let use_tree = builder.make_ast_mut(use_tree);
64+
let use_tree = builder.make_mut(use_tree);
6565

6666
let names_to_import = find_names_to_import(ctx, refs_in_target, imported_defs);
6767
let expanded = make::use_tree_list(names_to_import.iter().map(|n| {

crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub(crate) fn extract_struct_from_enum_variant(
7070
continue;
7171
}
7272
builder.edit_file(file_id);
73-
let source_file = builder.make_ast_mut(ctx.sema.parse(file_id));
73+
let source_file = builder.make_mut(ctx.sema.parse(file_id));
7474
let processed = process_references(
7575
ctx,
7676
&mut visited_modules_set,
@@ -84,8 +84,8 @@ pub(crate) fn extract_struct_from_enum_variant(
8484
});
8585
}
8686
builder.edit_file(ctx.frange.file_id);
87-
let source_file = builder.make_ast_mut(ctx.sema.parse(ctx.frange.file_id));
88-
let variant = builder.make_ast_mut(variant.clone());
87+
let source_file = builder.make_mut(ctx.sema.parse(ctx.frange.file_id));
88+
let variant = builder.make_mut(variant.clone());
8989
if let Some(references) = def_file_references {
9090
let processed = process_references(
9191
ctx,

crates/ide_assists/src/handlers/introduce_named_lifetime.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ fn generate_fn_def_assist(
8484
}
8585
};
8686
acc.add(AssistId(ASSIST_NAME, AssistKind::Refactor), ASSIST_LABEL, lifetime_loc, |builder| {
87-
let fn_def = builder.make_ast_mut(fn_def);
88-
let lifetime = builder.make_ast_mut(lifetime);
87+
let fn_def = builder.make_mut(fn_def);
88+
let lifetime = builder.make_mut(lifetime);
8989
let loc_needing_lifetime =
9090
loc_needing_lifetime.and_then(|it| it.make_mut(builder).to_position());
9191

@@ -107,8 +107,8 @@ fn generate_impl_def_assist(
107107
) -> Option<()> {
108108
let new_lifetime_param = generate_unique_lifetime_param_name(impl_def.generic_param_list())?;
109109
acc.add(AssistId(ASSIST_NAME, AssistKind::Refactor), ASSIST_LABEL, lifetime_loc, |builder| {
110-
let impl_def = builder.make_ast_mut(impl_def);
111-
let lifetime = builder.make_ast_mut(lifetime);
110+
let impl_def = builder.make_mut(impl_def);
111+
let lifetime = builder.make_mut(lifetime);
112112

113113
impl_def.get_or_create_generic_param_list().add_generic_param(
114114
make::lifetime_param(new_lifetime_param.clone()).clone_for_update().into(),
@@ -141,8 +141,8 @@ enum NeedsLifetime {
141141
impl NeedsLifetime {
142142
fn make_mut(self, builder: &mut AssistBuilder) -> Self {
143143
match self {
144-
Self::SelfParam(it) => Self::SelfParam(builder.make_ast_mut(it)),
145-
Self::RefType(it) => Self::RefType(builder.make_ast_mut(it)),
144+
Self::SelfParam(it) => Self::SelfParam(builder.make_mut(it)),
145+
Self::RefType(it) => Self::RefType(builder.make_mut(it)),
146146
}
147147
}
148148

crates/ide_assists/src/handlers/merge_imports.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<()
4747
target,
4848
|builder| {
4949
if let Some((to_replace, replacement, to_remove)) = imports {
50-
let to_replace = builder.make_ast_mut(to_replace);
51-
let to_remove = builder.make_ast_mut(to_remove);
50+
let to_replace = builder.make_mut(to_replace);
51+
let to_remove = builder.make_mut(to_remove);
5252

5353
ted::replace(to_replace.syntax(), replacement.syntax());
5454
to_remove.remove();
5555
}
5656

5757
if let Some((to_replace, replacement, to_remove)) = uses {
58-
let to_replace = builder.make_ast_mut(to_replace);
59-
let to_remove = builder.make_ast_mut(to_remove);
58+
let to_replace = builder.make_mut(to_replace);
59+
let to_remove = builder.make_mut(to_remove);
6060

6161
ted::replace(to_replace.syntax(), replacement.syntax());
6262
to_remove.remove()

crates/ide_assists/src/handlers/move_bounds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext
3636
"Move to where clause",
3737
target,
3838
|edit| {
39-
let type_param_list = edit.make_ast_mut(type_param_list);
40-
let parent = edit.make_mut(parent);
39+
let type_param_list = edit.make_mut(type_param_list);
40+
let parent = edit.make_syntax_mut(parent);
4141

4242
let where_clause: ast::WhereClause = match_ast! {
4343
match parent {

crates/ide_assists/src/handlers/pull_assignment_up.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ pub(crate) fn pull_assignment_up(acc: &mut Assists, ctx: &AssistContext) -> Opti
7474
let assignments: Vec<_> = collector
7575
.assignments
7676
.into_iter()
77-
.map(|(stmt, rhs)| (edit.make_ast_mut(stmt), rhs.clone_for_update()))
77+
.map(|(stmt, rhs)| (edit.make_mut(stmt), rhs.clone_for_update()))
7878
.collect();
7979

80-
let tgt = edit.make_ast_mut(tgt);
80+
let tgt = edit.make_mut(tgt);
8181

8282
for (stmt, rhs) in assignments {
8383
let mut stmt = stmt.syntax().clone();

crates/ide_assists/src/handlers/reorder_fields.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext) -> Option<(
7070
target,
7171
|builder| match fields {
7272
Either::Left((sorted, field_list)) => {
73-
replace(builder.make_ast_mut(field_list).fields(), sorted)
73+
replace(builder.make_mut(field_list).fields(), sorted)
7474
}
7575
Either::Right((sorted, field_list)) => {
76-
replace(builder.make_ast_mut(field_list).fields(), sorted)
76+
replace(builder.make_mut(field_list).fields(), sorted)
7777
}
7878
},
7979
)

crates/ide_assists/src/handlers/reorder_impl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ pub(crate) fn reorder_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
7979
"Sort methods",
8080
target,
8181
|builder| {
82-
let methods =
83-
methods.into_iter().map(|fn_| builder.make_ast_mut(fn_)).collect::<Vec<_>>();
82+
let methods = methods.into_iter().map(|fn_| builder.make_mut(fn_)).collect::<Vec<_>>();
8483
methods
8584
.into_iter()
8685
.zip(sorted)

crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ pub(crate) fn replace_impl_trait_with_generic(
3232
"Replace impl trait with generic",
3333
target,
3434
|edit| {
35-
let impl_trait_type = edit.make_ast_mut(impl_trait_type);
36-
let fn_ = edit.make_ast_mut(fn_);
35+
let impl_trait_type = edit.make_mut(impl_trait_type);
36+
let fn_ = edit.make_mut(fn_);
3737

3838
let type_param_name = suggest_name::for_generic_parameter(&impl_trait_type);
3939

crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub(crate) fn replace_qualified_name_with_use(
4040
|builder| {
4141
// Now that we've brought the name into scope, re-qualify all paths that could be
4242
// affected (that is, all paths inside the node we added the `use` to).
43-
let syntax = builder.make_mut(syntax.clone());
43+
let syntax = builder.make_syntax_mut(syntax.clone());
4444
if let Some(ref import_scope) = ImportScope::from(syntax.clone()) {
4545
shorten_paths(&syntax, &path.clone_for_update());
4646
insert_use(import_scope, path, ctx.config.insert_use);

0 commit comments

Comments
 (0)