diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-25 11:16:02 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-25 11:16:02 +0100 |
commit | 29fc409e7fe5b12dcf6bfbcca622d79c4c8fcb72 (patch) | |
tree | e42f7bd1490bca66e0786d5bf2b3194aeaa57a93 /crates/ra_assists/src/handlers/add_custom_impl.rs | |
parent | 27a7718880d93f55f905da606d108d3b3c682ab4 (diff) | |
parent | e87346950039a54c3f0b02d6056cbb92ca38eb28 (diff) |
Merge #4131
4131: Switch to text-size r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/handlers/add_custom_impl.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/add_custom_impl.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs index 15f9b216b..4ea26a550 100644 --- a/crates/ra_assists/src/handlers/add_custom_impl.rs +++ b/crates/ra_assists/src/handlers/add_custom_impl.rs | |||
@@ -2,7 +2,7 @@ use ra_syntax::{ | |||
2 | ast::{self, AstNode}, | 2 | ast::{self, AstNode}, |
3 | Direction, SmolStr, | 3 | Direction, SmolStr, |
4 | SyntaxKind::{IDENT, WHITESPACE}, | 4 | SyntaxKind::{IDENT, WHITESPACE}, |
5 | TextRange, TextUnit, | 5 | TextRange, TextSize, |
6 | }; | 6 | }; |
7 | use stdx::SepBy; | 7 | use stdx::SepBy; |
8 | 8 | ||
@@ -60,7 +60,6 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> { | |||
60 | .collect::<Vec<SmolStr>>(); | 60 | .collect::<Vec<SmolStr>>(); |
61 | let has_more_derives = !new_attr_input.is_empty(); | 61 | let has_more_derives = !new_attr_input.is_empty(); |
62 | let new_attr_input = new_attr_input.iter().sep_by(", ").surround_with("(", ")").to_string(); | 62 | let new_attr_input = new_attr_input.iter().sep_by(", ").surround_with("(", ")").to_string(); |
63 | let new_attr_input_len = new_attr_input.len(); | ||
64 | 63 | ||
65 | let mut buf = String::new(); | 64 | let mut buf = String::new(); |
66 | buf.push_str("\n\nimpl "); | 65 | buf.push_str("\n\nimpl "); |
@@ -70,8 +69,9 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> { | |||
70 | buf.push_str(" {\n"); | 69 | buf.push_str(" {\n"); |
71 | 70 | ||
72 | let cursor_delta = if has_more_derives { | 71 | let cursor_delta = if has_more_derives { |
72 | let delta = input.syntax().text_range().len() - TextSize::of(&new_attr_input); | ||
73 | edit.replace(input.syntax().text_range(), new_attr_input); | 73 | edit.replace(input.syntax().text_range(), new_attr_input); |
74 | input.syntax().text_range().len() - TextUnit::from_usize(new_attr_input_len) | 74 | delta |
75 | } else { | 75 | } else { |
76 | let attr_range = attr.syntax().text_range(); | 76 | let attr_range = attr.syntax().text_range(); |
77 | edit.delete(attr_range); | 77 | edit.delete(attr_range); |
@@ -81,13 +81,13 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> { | |||
81 | .next_sibling_or_token() | 81 | .next_sibling_or_token() |
82 | .filter(|t| t.kind() == WHITESPACE) | 82 | .filter(|t| t.kind() == WHITESPACE) |
83 | .map(|t| t.text_range()) | 83 | .map(|t| t.text_range()) |
84 | .unwrap_or_else(|| TextRange::from_to(TextUnit::from(0), TextUnit::from(0))); | 84 | .unwrap_or_else(|| TextRange::new(TextSize::from(0), TextSize::from(0))); |
85 | edit.delete(line_break_range); | 85 | edit.delete(line_break_range); |
86 | 86 | ||
87 | attr_range.len() + line_break_range.len() | 87 | attr_range.len() + line_break_range.len() |
88 | }; | 88 | }; |
89 | 89 | ||
90 | edit.set_cursor(start_offset + TextUnit::of_str(&buf) - cursor_delta); | 90 | edit.set_cursor(start_offset + TextSize::of(&buf) - cursor_delta); |
91 | buf.push_str("\n}"); | 91 | buf.push_str("\n}"); |
92 | edit.insert(start_offset, buf); | 92 | edit.insert(start_offset, buf); |
93 | }) | 93 | }) |