aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists')
-rw-r--r--crates/ra_assists/src/assists/raw_string.rs39
1 files changed, 35 insertions, 4 deletions
diff --git a/crates/ra_assists/src/assists/raw_string.rs b/crates/ra_assists/src/assists/raw_string.rs
index 86bbaeeef..6f4b66c31 100644
--- a/crates/ra_assists/src/assists/raw_string.rs
+++ b/crates/ra_assists/src/assists/raw_string.rs
@@ -155,10 +155,17 @@ fn count_hashes(s: &str) -> usize {
155} 155}
156 156
157fn find_usual_string_range(s: &str) -> Option<TextRange> { 157fn find_usual_string_range(s: &str) -> Option<TextRange> {
158 Some(TextRange::from_to( 158 let left_quote = s.find('"')?;
159 TextUnit::from(s.find('"')? as u32), 159 let right_quote = s.rfind('"')?;
160 TextUnit::from(s.rfind('"')? as u32), 160 if left_quote == right_quote {
161 )) 161 // `s` only contains one quote
162 None
163 } else {
164 Some(TextRange::from_to(
165 TextUnit::from(left_quote as u32),
166 TextUnit::from(right_quote as u32),
167 ))
168 }
162} 169}
163 170
164#[cfg(test)] 171#[cfg(test)]
@@ -268,6 +275,30 @@ string"###;
268 } 275 }
269 276
270 #[test] 277 #[test]
278 fn make_raw_string_not_works_on_partial_string() {
279 check_assist_not_applicable(
280 make_raw_string,
281 r#"
282 fn f() {
283 let s = "foo<|>
284 }
285 "#,
286 )
287 }
288
289 #[test]
290 fn make_usual_string_not_works_on_partial_string() {
291 check_assist_not_applicable(
292 make_usual_string,
293 r#"
294 fn main() {
295 let s = r#"bar<|>
296 }
297 "#,
298 )
299 }
300
301 #[test]
271 fn add_hash_target() { 302 fn add_hash_target() {
272 check_assist_target( 303 check_assist_target(
273 add_hash, 304 add_hash,