From b98c16a034620913f3dbc67bd3f48ad2686face7 Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Sun, 28 Jun 2020 18:36:05 -0400 Subject: Categorize assists --- crates/ra_assists/src/handlers/move_bounds.rs | 56 +++++++++++++++------------ 1 file changed, 32 insertions(+), 24 deletions(-) (limited to 'crates/ra_assists/src/handlers/move_bounds.rs') 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::{ T, }; -use crate::{AssistContext, AssistId, Assists}; +use crate::{AssistContext, AssistId, AssistKind, Assists}; // Assist: move_bounds_to_where_clause // @@ -50,29 +50,37 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext }; let target = type_param_list.syntax().text_range(); - acc.add(AssistId("move_bounds_to_where_clause"), "Move to where clause", target, |edit| { - let new_params = type_param_list - .type_params() - .filter(|it| it.type_bound_list().is_some()) - .map(|type_param| { - let without_bounds = type_param.remove_bounds(); - (type_param, without_bounds) - }); - - let new_type_param_list = type_param_list.replace_descendants(new_params); - edit.replace_ast(type_param_list.clone(), new_type_param_list); - - let where_clause = { - let predicates = type_param_list.type_params().filter_map(build_predicate); - make::where_clause(predicates) - }; - - let to_insert = match anchor.prev_sibling_or_token() { - Some(ref elem) if elem.kind() == WHITESPACE => format!("{} ", where_clause.syntax()), - _ => format!(" {}", where_clause.syntax()), - }; - edit.insert(anchor.text_range().start(), to_insert); - }) + acc.add( + AssistId("move_bounds_to_where_clause"), + AssistKind::RefactorRewrite, + "Move to where clause", + target, + |edit| { + let new_params = type_param_list + .type_params() + .filter(|it| it.type_bound_list().is_some()) + .map(|type_param| { + let without_bounds = type_param.remove_bounds(); + (type_param, without_bounds) + }); + + let new_type_param_list = type_param_list.replace_descendants(new_params); + edit.replace_ast(type_param_list.clone(), new_type_param_list); + + let where_clause = { + let predicates = type_param_list.type_params().filter_map(build_predicate); + make::where_clause(predicates) + }; + + let to_insert = match anchor.prev_sibling_or_token() { + Some(ref elem) if elem.kind() == WHITESPACE => { + format!("{} ", where_clause.syntax()) + } + _ => format!(" {}", where_clause.syntax()), + }; + edit.insert(anchor.text_range().start(), to_insert); + }, + ) } fn build_predicate(param: ast::TypeParam) -> Option { -- cgit v1.2.3 From 36cc81ac71e4246bf58a3758735cc68f7adb5e0f Mon Sep 17 00:00:00 2001 From: kjeremy Date: Thu, 2 Jul 2020 17:48:35 -0400 Subject: Move AssistKind into AssistId --- crates/ra_assists/src/handlers/move_bounds.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'crates/ra_assists/src/handlers/move_bounds.rs') diff --git a/crates/ra_assists/src/handlers/move_bounds.rs b/crates/ra_assists/src/handlers/move_bounds.rs index bcedd39a8..ba3dafb99 100644 --- a/crates/ra_assists/src/handlers/move_bounds.rs +++ b/crates/ra_assists/src/handlers/move_bounds.rs @@ -51,8 +51,7 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext let target = type_param_list.syntax().text_range(); acc.add( - AssistId("move_bounds_to_where_clause"), - AssistKind::RefactorRewrite, + AssistId("move_bounds_to_where_clause", AssistKind::RefactorRewrite), "Move to where clause", target, |edit| { -- cgit v1.2.3