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/unwrap_block.rs | 66 +++++++++++++++----------- 1 file changed, 39 insertions(+), 27 deletions(-) (limited to 'crates/ra_assists/src/handlers/unwrap_block.rs') diff --git a/crates/ra_assists/src/handlers/unwrap_block.rs b/crates/ra_assists/src/handlers/unwrap_block.rs index 1fb13f481..a66fba7c3 100644 --- a/crates/ra_assists/src/handlers/unwrap_block.rs +++ b/crates/ra_assists/src/handlers/unwrap_block.rs @@ -7,7 +7,7 @@ use ra_syntax::{ AstNode, TextRange, T, }; -use crate::{AssistContext, AssistId, Assists}; +use crate::{AssistContext, AssistId, AssistKind, Assists}; // Assist: unwrap_block // @@ -50,35 +50,47 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()> let ancestor_then_branch = ancestor.then_branch()?; let target = then_branch.syntax().text_range(); - return acc.add(assist_id, assist_label, target, |edit| { - let range_to_del_else_if = TextRange::new( - ancestor_then_branch.syntax().text_range().end(), - l_curly_token.text_range().start(), - ); - let range_to_del_rest = TextRange::new( - then_branch.syntax().text_range().end(), - if_expr.syntax().text_range().end(), - ); - - edit.delete(range_to_del_rest); - edit.delete(range_to_del_else_if); - edit.replace( - target, - update_expr_string(then_branch.to_string(), &[' ', '{']), - ); - }); + return acc.add( + assist_id, + AssistKind::Refactor, + assist_label, + target, + |edit| { + let range_to_del_else_if = TextRange::new( + ancestor_then_branch.syntax().text_range().end(), + l_curly_token.text_range().start(), + ); + let range_to_del_rest = TextRange::new( + then_branch.syntax().text_range().end(), + if_expr.syntax().text_range().end(), + ); + + edit.delete(range_to_del_rest); + edit.delete(range_to_del_else_if); + edit.replace( + target, + update_expr_string(then_branch.to_string(), &[' ', '{']), + ); + }, + ); } } else { let target = block.syntax().text_range(); - return acc.add(assist_id, assist_label, target, |edit| { - let range_to_del = TextRange::new( - then_branch.syntax().text_range().end(), - l_curly_token.text_range().start(), - ); + return acc.add( + assist_id, + AssistKind::RefactorRewrite, + assist_label, + target, + |edit| { + let range_to_del = TextRange::new( + then_branch.syntax().text_range().end(), + l_curly_token.text_range().start(), + ); - edit.delete(range_to_del); - edit.replace(target, update_expr_string(block.to_string(), &[' ', '{'])); - }); + edit.delete(range_to_del); + edit.replace(target, update_expr_string(block.to_string(), &[' ', '{'])); + }, + ); } } _ => return None, @@ -86,7 +98,7 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()> let unwrapped = unwrap_trivial_block(block); let target = unwrapped.syntax().text_range(); - acc.add(assist_id, assist_label, target, |builder| { + acc.add(assist_id, AssistKind::RefactorRewrite, assist_label, target, |builder| { builder.replace( parent.syntax().text_range(), update_expr_string(unwrapped.to_string(), &[' ', '{', '\n']), -- cgit v1.2.3