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 2df48a838..cb3a1e6e9 100644
--- a/crates/ra_assists/src/assists/raw_string.rs
+++ b/crates/ra_assists/src/assists/raw_string.rs
@@ -159,10 +159,17 @@ fn count_hashes(s: &str) -> usize {
159} 159}
160 160
161fn find_usual_string_range(s: &str) -> Option<TextRange> { 161fn find_usual_string_range(s: &str) -> Option<TextRange> {
162 Some(TextRange::from_to( 162 let left_quote = s.find('"')?;
163 TextUnit::from(s.find('"')? as u32), 163 let right_quote = s.rfind('"')?;
164 TextUnit::from(s.rfind('"')? as u32), 164 if left_quote == right_quote {
165 )) 165 // `s` only contains one quote
166 None
167 } else {
168 Some(TextRange::from_to(
169 TextUnit::from(left_quote as u32),
170 TextUnit::from(right_quote as u32),
171 ))
172 }
166} 173}
167 174
168#[cfg(test)] 175#[cfg(test)]
@@ -272,6 +279,30 @@ string"###;
272 } 279 }
273 280
274 #[test] 281 #[test]
282 fn make_raw_string_not_works_on_partial_string() {
283 check_assist_not_applicable(
284 make_raw_string,
285 r#"
286 fn f() {
287 let s = "foo<|>
288 }
289 "#,
290 )
291 }
292
293 #[test]
294 fn make_usual_string_not_works_on_partial_string() {
295 check_assist_not_applicable(
296 make_usual_string,
297 r#"
298 fn main() {
299 let s = r#"bar<|>
300 }
301 "#,
302 )
303 }
304
305 #[test]
275 fn add_hash_target() { 306 fn add_hash_target() {
276 check_assist_target( 307 check_assist_target(
277 add_hash, 308 add_hash,