From 63a462f37ca584e1a585a69e30823ce25d4d252f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Apr 2020 00:57:47 +0200 Subject: Switch to TryFrom --- crates/ra_assists/src/handlers/add_custom_impl.rs | 4 ++-- crates/ra_assists/src/handlers/add_function.rs | 2 +- crates/ra_assists/src/handlers/add_new.rs | 4 ++-- crates/ra_assists/src/handlers/merge_match_arms.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_assists') diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs index 7bb90dba3..4ea26a550 100644 --- a/crates/ra_assists/src/handlers/add_custom_impl.rs +++ b/crates/ra_assists/src/handlers/add_custom_impl.rs @@ -60,7 +60,6 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option { .collect::>(); let has_more_derives = !new_attr_input.is_empty(); let new_attr_input = new_attr_input.iter().sep_by(", ").surround_with("(", ")").to_string(); - let new_attr_input_len = new_attr_input.len(); let mut buf = String::new(); buf.push_str("\n\nimpl "); @@ -70,8 +69,9 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option { buf.push_str(" {\n"); let cursor_delta = if has_more_derives { + let delta = input.syntax().text_range().len() - TextSize::of(&new_attr_input); edit.replace(input.syntax().text_range(), new_attr_input); - input.syntax().text_range().len() - TextSize::from_usize(new_attr_input_len) + delta } else { let attr_range = attr.syntax().text_range(); edit.delete(attr_range); diff --git a/crates/ra_assists/src/handlers/add_function.rs b/crates/ra_assists/src/handlers/add_function.rs index 7a8f5705f..6c7456579 100644 --- a/crates/ra_assists/src/handlers/add_function.rs +++ b/crates/ra_assists/src/handlers/add_function.rs @@ -129,7 +129,7 @@ impl FunctionBuilder { let fn_def = indent_once.increase_indent(fn_def); let fn_def = ast::make::add_trailing_newlines(1, fn_def); let fn_def = indent.increase_indent(fn_def); - (fn_def, it.syntax().text_range().start() + TextSize::from_usize(1)) + (fn_def, it.syntax().text_range().start() + TextSize::of('{')) } }; diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs index 0698cce88..0f9174a29 100644 --- a/crates/ra_assists/src/handlers/add_new.rs +++ b/crates/ra_assists/src/handlers/add_new.rs @@ -77,13 +77,13 @@ pub(crate) fn add_new(ctx: AssistCtx) -> Option { .text_range() .end(); - Some((start, TextSize::from_usize(1))) + Some((start, TextSize::of("\n"))) }) .unwrap_or_else(|| { buf = generate_impl_text(&strukt, &buf); let start = strukt.syntax().text_range().end(); - (start, TextSize::from_usize(3)) + (start, TextSize::of("\n}\n")) }); edit.set_cursor(start_offset + TextSize::of(&buf) - end_offset); diff --git a/crates/ra_assists/src/handlers/merge_match_arms.rs b/crates/ra_assists/src/handlers/merge_match_arms.rs index cd0416f01..5a77d3dbc 100644 --- a/crates/ra_assists/src/handlers/merge_match_arms.rs +++ b/crates/ra_assists/src/handlers/merge_match_arms.rs @@ -89,7 +89,7 @@ pub(crate) fn merge_match_arms(ctx: AssistCtx) -> Option { edit.target(current_text_range); edit.set_cursor(match cursor_pos { - CursorPos::InExpr(back_offset) => start + TextSize::from_usize(arm.len()) - back_offset, + CursorPos::InExpr(back_offset) => start + TextSize::of(&arm) - back_offset, CursorPos::InPat(offset) => offset, }); edit.replace(TextRange::new(start, end), arm); -- cgit v1.2.3