mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Switch to TryFrom
This commit is contained in:
parent
dc2151085e
commit
63a462f37c
13 changed files with 63 additions and 53 deletions
|
@ -60,7 +60,6 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
|
|||
.collect::<Vec<SmolStr>>();
|
||||
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<Assist> {
|
|||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue