aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src/handlers/move_bounds.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-03-23 14:31:19 +0000
committerAleksey Kladov <[email protected]>2021-03-23 14:31:19 +0000
commitb83c7eedccea4c9cb35b1d1cc58231f07a5e3ba2 (patch)
treeb6a237b53f65aaf96fc65707580ef41ab9a73d2d /crates/ide_assists/src/handlers/move_bounds.rs
parent258afb8fb8331e43a75e4f19df255d85d2430be7 (diff)
Tweak assits API to fit mutable syntax trees
changelog: skip
Diffstat (limited to 'crates/ide_assists/src/handlers/move_bounds.rs')
-rw-r--r--crates/ide_assists/src/handlers/move_bounds.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/crates/ide_assists/src/handlers/move_bounds.rs b/crates/ide_assists/src/handlers/move_bounds.rs
index b5dec8014..011a28d44 100644
--- a/crates/ide_assists/src/handlers/move_bounds.rs
+++ b/crates/ide_assists/src/handlers/move_bounds.rs
@@ -21,7 +21,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
21// } 21// }
22// ``` 22// ```
23pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 23pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
24 let type_param_list = ctx.find_node_at_offset::<ast::GenericParamList>()?.clone_for_update(); 24 let type_param_list = ctx.find_node_at_offset::<ast::GenericParamList>()?;
25 25
26 let mut type_params = type_param_list.type_params(); 26 let mut type_params = type_param_list.type_params();
27 if type_params.all(|p| p.type_bound_list().is_none()) { 27 if type_params.all(|p| p.type_bound_list().is_none()) {
@@ -29,7 +29,6 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext
29 } 29 }
30 30
31 let parent = type_param_list.syntax().parent()?; 31 let parent = type_param_list.syntax().parent()?;
32 let original_parent_range = parent.text_range();
33 32
34 let target = type_param_list.syntax().text_range(); 33 let target = type_param_list.syntax().text_range();
35 acc.add( 34 acc.add(
@@ -37,6 +36,9 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext
37 "Move to where clause", 36 "Move to where clause",
38 target, 37 target,
39 |edit| { 38 |edit| {
39 let type_param_list = edit.make_ast_mut(type_param_list);
40 let parent = edit.make_mut(parent);
41
40 let where_clause: ast::WhereClause = match_ast! { 42 let where_clause: ast::WhereClause = match_ast! {
41 match parent { 43 match parent {
42 ast::Fn(it) => it.get_or_create_where_clause(), 44 ast::Fn(it) => it.get_or_create_where_clause(),
@@ -56,8 +58,6 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext
56 tbl.remove() 58 tbl.remove()
57 } 59 }
58 } 60 }
59
60 edit.replace(original_parent_range, parent.to_string())
61 }, 61 },
62 ) 62 )
63} 63}