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/raw_string.rs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'crates/ra_assists/src/assists/raw_string.rs') diff --git a/crates/ra_assists/src/assists/raw_string.rs b/crates/ra_assists/src/assists/raw_string.rs index 2df48a838..86bbaeeef 100644 --- a/crates/ra_assists/src/assists/raw_string.rs +++ b/crates/ra_assists/src/assists/raw_string.rs @@ -22,7 +22,7 @@ use crate::{Assist, AssistCtx, AssistId}; // r#"Hello, World!"#; // } // ``` -pub(crate) fn make_raw_string(mut ctx: AssistCtx) -> Option { +pub(crate) fn make_raw_string(ctx: AssistCtx) -> Option { let token = ctx.find_token_at_offset(STRING)?; let text = token.text().as_str(); let usual_string_range = find_usual_string_range(text)?; @@ -41,7 +41,7 @@ pub(crate) fn make_raw_string(mut ctx: AssistCtx) -> Option) -> Option) -> Option) -> Option { +pub(crate) fn make_usual_string(ctx: AssistCtx) -> Option { let token = ctx.find_token_at_offset(RAW_STRING)?; let text = token.text().as_str(); let usual_string_range = find_usual_string_range(text)?; - ctx.add_action(AssistId("make_usual_string"), "make usual string", |edit| { + ctx.add_assist(AssistId("make_usual_string"), "make usual string", |edit| { edit.target(token.text_range()); // parse inside string to escape `"` let start_of_inside = usual_string_range.start().to_usize() + 1; @@ -80,8 +79,7 @@ pub(crate) fn make_usual_string(mut ctx: AssistCtx) -> Option< let inside_str = &text[start_of_inside..end_of_inside]; let escaped = inside_str.escape_default().to_string(); edit.replace(token.text_range(), format!("\"{}\"", escaped)); - }); - ctx.build() + }) } // Assist: add_hash @@ -99,14 +97,13 @@ pub(crate) fn make_usual_string(mut ctx: AssistCtx) -> Option< // r##"Hello, World!"##; // } // ``` -pub(crate) fn add_hash(mut ctx: AssistCtx) -> Option { +pub(crate) fn add_hash(ctx: AssistCtx) -> Option { let token = ctx.find_token_at_offset(RAW_STRING)?; - ctx.add_action(AssistId("add_hash"), "add hash to raw string", |edit| { + ctx.add_assist(AssistId("add_hash"), "add hash to raw string", |edit| { edit.target(token.text_range()); edit.insert(token.text_range().start() + TextUnit::of_char('r'), "#"); edit.insert(token.text_range().end(), "#"); - }); - ctx.build() + }) } // Assist: remove_hash @@ -124,14 +121,14 @@ pub(crate) fn add_hash(mut ctx: AssistCtx) -> Option { // r"Hello, World!"; // } // ``` -pub(crate) fn remove_hash(mut ctx: AssistCtx) -> Option { +pub(crate) fn remove_hash(ctx: AssistCtx) -> Option { let token = ctx.find_token_at_offset(RAW_STRING)?; let text = token.text().as_str(); if text.starts_with("r\"") { // no hash to remove return None; } - ctx.add_action(AssistId("remove_hash"), "remove hash from raw string", |edit| { + ctx.add_assist(AssistId("remove_hash"), "remove hash from raw string", |edit| { edit.target(token.text_range()); let result = &text[2..text.len() - 1]; let result = if result.starts_with("\"") { @@ -142,8 +139,7 @@ pub(crate) fn remove_hash(mut ctx: AssistCtx) -> Option usize { -- cgit v1.2.3