From cda6355de23825c201d02e6062cb2dd414e98bf9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 27 Oct 2019 17:35:37 +0300 Subject: simplify AssistCtx API We never actually use ability to create multiple actions out of a single context --- crates/ra_assists/src/assists/move_guard.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'crates/ra_assists/src/assists/move_guard.rs') diff --git a/crates/ra_assists/src/assists/move_guard.rs b/crates/ra_assists/src/assists/move_guard.rs index e820a73c8..b49ec6172 100644 --- a/crates/ra_assists/src/assists/move_guard.rs +++ b/crates/ra_assists/src/assists/move_guard.rs @@ -32,7 +32,7 @@ use crate::{Assist, AssistCtx, AssistId}; // } // } // ``` -pub(crate) fn move_guard_to_arm_body(mut ctx: AssistCtx) -> Option { +pub(crate) fn move_guard_to_arm_body(ctx: AssistCtx) -> Option { let match_arm = ctx.find_node_at_offset::()?; let guard = match_arm.guard()?; let space_before_guard = guard.syntax().prev_sibling_or_token(); @@ -41,7 +41,7 @@ pub(crate) fn move_guard_to_arm_body(mut ctx: AssistCtx) -> Op let arm_expr = match_arm.expr()?; let buf = format!("if {} {{ {} }}", guard_conditions.syntax().text(), arm_expr.syntax().text()); - ctx.add_action(AssistId("move_guard_to_arm_body"), "move guard to arm body", |edit| { + ctx.add_assist(AssistId("move_guard_to_arm_body"), "move guard to arm body", |edit| { edit.target(guard.syntax().text_range()); let offseting_amount = match space_before_guard.and_then(|it| it.into_token()) { Some(tok) => { @@ -61,8 +61,7 @@ pub(crate) fn move_guard_to_arm_body(mut ctx: AssistCtx) -> Op edit.set_cursor( arm_expr.syntax().text_range().start() + TextUnit::from(3) - offseting_amount, ); - }); - ctx.build() + }) } // Assist: move_arm_cond_to_match_guard @@ -90,7 +89,7 @@ pub(crate) fn move_guard_to_arm_body(mut ctx: AssistCtx) -> Op // } // } // ``` -pub(crate) fn move_arm_cond_to_match_guard(mut ctx: AssistCtx) -> Option { +pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx) -> Option { let match_arm: MatchArm = ctx.find_node_at_offset::()?; let last_match_pat = match_arm.pats().last()?; @@ -110,7 +109,7 @@ pub(crate) fn move_arm_cond_to_match_guard(mut ctx: AssistCtx) let buf = format!(" if {}", cond.syntax().text()); - ctx.add_action( + ctx.add_assist( AssistId("move_arm_cond_to_match_guard"), "move condition to match guard", |edit| { @@ -127,8 +126,7 @@ pub(crate) fn move_arm_cond_to_match_guard(mut ctx: AssistCtx) edit.insert(last_match_pat.syntax().text_range().end(), buf); edit.set_cursor(last_match_pat.syntax().text_range().end() + TextUnit::from(1)); }, - ); - ctx.build() + ) } #[cfg(test)] -- cgit v1.2.3