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 From 2984da672e0c73d56501c6b6e4d19fd28152b5eb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 11:42:51 +0200 Subject: Split ItemList & AssocItemList --- crates/ra_assists/src/handlers/move_bounds.rs | 4 ++-- 1 file changed, 2 insertions(+), 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 ba3dafb99..6b73fff44 100644 --- a/crates/ra_assists/src/handlers/move_bounds.rs +++ b/crates/ra_assists/src/handlers/move_bounds.rs @@ -38,8 +38,8 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext let anchor = match_ast! { match parent { ast::FnDef(it) => it.body()?.syntax().clone().into(), - ast::TraitDef(it) => it.item_list()?.syntax().clone().into(), - ast::ImplDef(it) => it.item_list()?.syntax().clone().into(), + ast::TraitDef(it) => it.assoc_item_list()?.syntax().clone().into(), + ast::ImplDef(it) => it.assoc_item_list()?.syntax().clone().into(), ast::EnumDef(it) => it.variant_list()?.syntax().clone().into(), ast::StructDef(it) => { it.syntax().children_with_tokens() -- cgit v1.2.3 From 1142112c70b705f59b7d559d9d72cdc831865158 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 14:51:08 +0200 Subject: Rename FnDef -> Fn --- crates/ra_assists/src/handlers/move_bounds.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 6b73fff44..dae6198ed 100644 --- a/crates/ra_assists/src/handlers/move_bounds.rs +++ b/crates/ra_assists/src/handlers/move_bounds.rs @@ -37,7 +37,7 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext let anchor = match_ast! { match parent { - ast::FnDef(it) => it.body()?.syntax().clone().into(), + ast::Fn(it) => it.body()?.syntax().clone().into(), ast::TraitDef(it) => it.assoc_item_list()?.syntax().clone().into(), ast::ImplDef(it) => it.assoc_item_list()?.syntax().clone().into(), ast::EnumDef(it) => it.variant_list()?.syntax().clone().into(), -- cgit v1.2.3 From 28ef4c375a9f56d69daf885504aea3df7012bb81 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 15:36:21 +0200 Subject: Rename TypeParamList -> GenericParamList --- crates/ra_assists/src/handlers/move_bounds.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 dae6198ed..69ce90fbc 100644 --- a/crates/ra_assists/src/handlers/move_bounds.rs +++ b/crates/ra_assists/src/handlers/move_bounds.rs @@ -23,7 +23,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // } // ``` pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { - let type_param_list = ctx.find_node_at_offset::()?; + let type_param_list = ctx.find_node_at_offset::()?; let mut type_params = type_param_list.type_params(); if type_params.all(|p| p.type_bound_list().is_none()) { -- cgit v1.2.3 From 0a9e3ccc262fbcbd4cdaab30384f8cb71584544b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 16:49:13 +0200 Subject: Rename FieldDef -> Field --- crates/ra_assists/src/handlers/move_bounds.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 69ce90fbc..15327facb 100644 --- a/crates/ra_assists/src/handlers/move_bounds.rs +++ b/crates/ra_assists/src/handlers/move_bounds.rs @@ -43,7 +43,7 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext ast::EnumDef(it) => it.variant_list()?.syntax().clone().into(), ast::StructDef(it) => { it.syntax().children_with_tokens() - .find(|it| it.kind() == RECORD_FIELD_DEF_LIST || it.kind() == T![;])? + .find(|it| it.kind() == RECORD_FIELD_LIST || it.kind() == T![;])? }, _ => return None } -- cgit v1.2.3 From 216a5344c8ef3c3e430d2761dc8b1a7b60250a15 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:50:40 +0200 Subject: Rename StructDef -> Struct --- crates/ra_assists/src/handlers/move_bounds.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 15327facb..3b82477c5 100644 --- a/crates/ra_assists/src/handlers/move_bounds.rs +++ b/crates/ra_assists/src/handlers/move_bounds.rs @@ -41,7 +41,7 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext ast::TraitDef(it) => it.assoc_item_list()?.syntax().clone().into(), ast::ImplDef(it) => it.assoc_item_list()?.syntax().clone().into(), ast::EnumDef(it) => it.variant_list()?.syntax().clone().into(), - ast::StructDef(it) => { + ast::Struct(it) => { it.syntax().children_with_tokens() .find(|it| it.kind() == RECORD_FIELD_LIST || it.kind() == T![;])? }, -- cgit v1.2.3 From 609680ef97dbf82c07b6b06e21aa366423892304 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 17:52:53 +0200 Subject: Rename EnumDef -> Enum --- crates/ra_assists/src/handlers/move_bounds.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 3b82477c5..84ac75fa8 100644 --- a/crates/ra_assists/src/handlers/move_bounds.rs +++ b/crates/ra_assists/src/handlers/move_bounds.rs @@ -40,7 +40,7 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext ast::Fn(it) => it.body()?.syntax().clone().into(), ast::TraitDef(it) => it.assoc_item_list()?.syntax().clone().into(), ast::ImplDef(it) => it.assoc_item_list()?.syntax().clone().into(), - ast::EnumDef(it) => it.variant_list()?.syntax().clone().into(), + ast::Enum(it) => it.variant_list()?.syntax().clone().into(), ast::Struct(it) => { it.syntax().children_with_tokens() .find(|it| it.kind() == RECORD_FIELD_LIST || it.kind() == T![;])? -- cgit v1.2.3 From c83467796b6c7365ea4f41900d74444384a9e618 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:17:28 +0200 Subject: Finalize Trait grammar --- crates/ra_assists/src/handlers/move_bounds.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 84ac75fa8..fd1d87423 100644 --- a/crates/ra_assists/src/handlers/move_bounds.rs +++ b/crates/ra_assists/src/handlers/move_bounds.rs @@ -38,7 +38,7 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext let anchor = match_ast! { match parent { ast::Fn(it) => it.body()?.syntax().clone().into(), - ast::TraitDef(it) => it.assoc_item_list()?.syntax().clone().into(), + ast::Trait(it) => it.assoc_item_list()?.syntax().clone().into(), ast::ImplDef(it) => it.assoc_item_list()?.syntax().clone().into(), ast::Enum(it) => it.variant_list()?.syntax().clone().into(), ast::Struct(it) => { -- cgit v1.2.3 From c5798c4d75aa807aec47208a49101bdec3affcca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 Jul 2020 18:28:28 +0200 Subject: Finalize impl Grammar --- crates/ra_assists/src/handlers/move_bounds.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 fd1d87423..6d394443e 100644 --- a/crates/ra_assists/src/handlers/move_bounds.rs +++ b/crates/ra_assists/src/handlers/move_bounds.rs @@ -39,7 +39,7 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext match parent { ast::Fn(it) => it.body()?.syntax().clone().into(), ast::Trait(it) => it.assoc_item_list()?.syntax().clone().into(), - ast::ImplDef(it) => it.assoc_item_list()?.syntax().clone().into(), + ast::Impl(it) => it.assoc_item_list()?.syntax().clone().into(), ast::Enum(it) => it.variant_list()?.syntax().clone().into(), ast::Struct(it) => { it.syntax().children_with_tokens() -- cgit v1.2.3