diff options
author | Domantas Jadenkus <[email protected]> | 2021-03-03 21:20:18 +0000 |
---|---|---|
committer | Domantas Jadenkus <[email protected]> | 2021-03-03 21:20:18 +0000 |
commit | 5bb4aec05f547cce8d9752a0e856b9b91e911643 (patch) | |
tree | e32289c9870fe39e12552aefd7cd033ade3d89fe /crates/ide_assists/src/handlers | |
parent | d0fa7abc5044471b951149aa35244620db847ff9 (diff) |
preserve escape sequences when replacing string with char
Diffstat (limited to 'crates/ide_assists/src/handlers')
-rw-r--r-- | crates/ide_assists/src/handlers/replace_string_with_char.rs | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/crates/ide_assists/src/handlers/replace_string_with_char.rs b/crates/ide_assists/src/handlers/replace_string_with_char.rs index 317318c24..303c0dcbe 100644 --- a/crates/ide_assists/src/handlers/replace_string_with_char.rs +++ b/crates/ide_assists/src/handlers/replace_string_with_char.rs | |||
@@ -31,7 +31,9 @@ pub(crate) fn replace_string_with_char(acc: &mut Assists, ctx: &AssistContext) - | |||
31 | "Replace string with char", | 31 | "Replace string with char", |
32 | target, | 32 | target, |
33 | |edit| { | 33 | |edit| { |
34 | edit.replace(token.syntax().text_range(), format!("'{}'", value)); | 34 | let token_text = token.syntax().text(); |
35 | let inner_text = &token_text[1..token_text.len() - 1]; | ||
36 | edit.replace(token.syntax().text_range(), format!("'{}'", inner_text)); | ||
35 | }, | 37 | }, |
36 | ) | 38 | ) |
37 | } | 39 | } |
@@ -134,4 +136,38 @@ mod tests { | |||
134 | "##, | 136 | "##, |
135 | ) | 137 | ) |
136 | } | 138 | } |
139 | |||
140 | #[test] | ||
141 | fn replace_string_with_char_newline() { | ||
142 | check_assist( | ||
143 | replace_string_with_char, | ||
144 | r#" | ||
145 | fn f() { | ||
146 | find($0"\n"); | ||
147 | } | ||
148 | "#, | ||
149 | r##" | ||
150 | fn f() { | ||
151 | find('\n'); | ||
152 | } | ||
153 | "##, | ||
154 | ) | ||
155 | } | ||
156 | |||
157 | #[test] | ||
158 | fn replace_string_with_char_unicode_escape() { | ||
159 | check_assist( | ||
160 | replace_string_with_char, | ||
161 | r#" | ||
162 | fn f() { | ||
163 | find($0"\u{7FFF}"); | ||
164 | } | ||
165 | "#, | ||
166 | r##" | ||
167 | fn f() { | ||
168 | find('\u{7FFF}'); | ||
169 | } | ||
170 | "##, | ||
171 | ) | ||
172 | } | ||
137 | } | 173 | } |