diff options
author | Jeremy Kolb <[email protected]> | 2020-06-28 23:36:05 +0100 |
---|---|---|
committer | kjeremy <[email protected]> | 2020-07-02 22:13:02 +0100 |
commit | b98c16a034620913f3dbc67bd3f48ad2686face7 (patch) | |
tree | 10f90c96791cfd82bb160a1a5c7474ccc17d5b8b /crates/ra_assists/src/handlers/move_bounds.rs | |
parent | 4cb8bf03c588dcf244d25785de3878b6ef3f7958 (diff) |
Categorize assists
Diffstat (limited to 'crates/ra_assists/src/handlers/move_bounds.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/move_bounds.rs | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/crates/ra_assists/src/handlers/move_bounds.rs b/crates/ra_assists/src/handlers/move_bounds.rs index be2a7eddc..bcedd39a8 100644 --- a/crates/ra_assists/src/handlers/move_bounds.rs +++ b/crates/ra_assists/src/handlers/move_bounds.rs | |||
@@ -5,7 +5,7 @@ use ra_syntax::{ | |||
5 | T, | 5 | T, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use crate::{AssistContext, AssistId, Assists}; | 8 | use crate::{AssistContext, AssistId, AssistKind, Assists}; |
9 | 9 | ||
10 | // Assist: move_bounds_to_where_clause | 10 | // Assist: move_bounds_to_where_clause |
11 | // | 11 | // |
@@ -50,29 +50,37 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext | |||
50 | }; | 50 | }; |
51 | 51 | ||
52 | let target = type_param_list.syntax().text_range(); | 52 | let target = type_param_list.syntax().text_range(); |
53 | acc.add(AssistId("move_bounds_to_where_clause"), "Move to where clause", target, |edit| { | 53 | acc.add( |
54 | let new_params = type_param_list | 54 | AssistId("move_bounds_to_where_clause"), |
55 | .type_params() | 55 | AssistKind::RefactorRewrite, |
56 | .filter(|it| it.type_bound_list().is_some()) | 56 | "Move to where clause", |
57 | .map(|type_param| { | 57 | target, |
58 | let without_bounds = type_param.remove_bounds(); | 58 | |edit| { |
59 | (type_param, without_bounds) | 59 | let new_params = type_param_list |
60 | }); | 60 | .type_params() |
61 | 61 | .filter(|it| it.type_bound_list().is_some()) | |
62 | let new_type_param_list = type_param_list.replace_descendants(new_params); | 62 | .map(|type_param| { |
63 | edit.replace_ast(type_param_list.clone(), new_type_param_list); | 63 | let without_bounds = type_param.remove_bounds(); |
64 | 64 | (type_param, without_bounds) | |
65 | let where_clause = { | 65 | }); |
66 | let predicates = type_param_list.type_params().filter_map(build_predicate); | 66 | |
67 | make::where_clause(predicates) | 67 | let new_type_param_list = type_param_list.replace_descendants(new_params); |
68 | }; | 68 | edit.replace_ast(type_param_list.clone(), new_type_param_list); |
69 | 69 | ||
70 | let to_insert = match anchor.prev_sibling_or_token() { | 70 | let where_clause = { |
71 | Some(ref elem) if elem.kind() == WHITESPACE => format!("{} ", where_clause.syntax()), | 71 | let predicates = type_param_list.type_params().filter_map(build_predicate); |
72 | _ => format!(" {}", where_clause.syntax()), | 72 | make::where_clause(predicates) |
73 | }; | 73 | }; |
74 | edit.insert(anchor.text_range().start(), to_insert); | 74 | |
75 | }) | 75 | let to_insert = match anchor.prev_sibling_or_token() { |
76 | Some(ref elem) if elem.kind() == WHITESPACE => { | ||
77 | format!("{} ", where_clause.syntax()) | ||
78 | } | ||
79 | _ => format!(" {}", where_clause.syntax()), | ||
80 | }; | ||
81 | edit.insert(anchor.text_range().start(), to_insert); | ||
82 | }, | ||
83 | ) | ||
76 | } | 84 | } |
77 | 85 | ||
78 | fn build_predicate(param: ast::TypeParam) -> Option<ast::WherePred> { | 86 | fn build_predicate(param: ast::TypeParam) -> Option<ast::WherePred> { |