aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorIgor Aleksanov <[email protected]>2020-09-12 16:09:00 +0100
committerIgor Aleksanov <[email protected]>2020-10-02 10:42:39 +0100
commitcd3d654f60dad121fb44dc7f2874003ee6f73a55 (patch)
tree2beb72cb83754e1579c96a307e22678cf542919b /crates
parente447b3a4a2bf089e5e3a190a532c17a4572ea013 (diff)
Simplify is_string_literal function
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/completion/complete_postfix/format_like.rs14
1 files changed, 5 insertions, 9 deletions
diff --git a/crates/ide/src/completion/complete_postfix/format_like.rs b/crates/ide/src/completion/complete_postfix/format_like.rs
index 6be3c2c92..8a16147ed 100644
--- a/crates/ide/src/completion/complete_postfix/format_like.rs
+++ b/crates/ide/src/completion/complete_postfix/format_like.rs
@@ -51,11 +51,7 @@ fn is_string_literal(item: &str) -> bool {
51 if item.len() < 2 { 51 if item.len() < 2 {
52 return false; 52 return false;
53 } 53 }
54 if item.chars().nth(0) != Some('"') || item.chars().nth(item.len() - 1) != Some('"') { 54 item.starts_with("\"") && item.ends_with("\"")
55 return false;
56 }
57
58 true
59} 55}
60 56
61/// Parser for a format-like string. It is more allowing in terms of string contents, 57/// Parser for a format-like string. It is more allowing in terms of string contents,
@@ -269,8 +265,8 @@ mod tests {
269 ("{correct}}}", Some(("{}}}", vec!["correct"]))), 265 ("{correct}}}", Some(("{}}}", vec!["correct"]))),
270 ("{correct}}}}}", Some(("{}}}}}", vec!["correct"]))), 266 ("{correct}}}}}", Some(("{}}}}}", vec!["correct"]))),
271 ("{incorrect}}", None), 267 ("{incorrect}}", None),
272 ("placeholders {} {}", Some(("placeholders {} {}", vec!["$0", "$1"]))), 268 ("placeholders {} {}", Some(("placeholders {} {}", vec!["$1", "$2"]))),
273 ("mixed {} {2 + 2} {}", Some(("mixed {} {} {}", vec!["$0", "2 + 2", "$1"]))), 269 ("mixed {} {2 + 2} {}", Some(("mixed {} {} {}", vec!["$1", "2 + 2", "$2"]))),
274 ( 270 (
275 "{SomeStruct { val_a: 0, val_b: 1 }}", 271 "{SomeStruct { val_a: 0, val_b: 1 }}",
276 Some(("{}", vec!["SomeStruct { val_a: 0, val_b: 1 }"])), 272 Some(("{}", vec!["SomeStruct { val_a: 0, val_b: 1 }"])),
@@ -309,11 +305,11 @@ mod tests {
309 #[test] 305 #[test]
310 fn test_into_suggestion() { 306 fn test_into_suggestion() {
311 let test_vector = &[ 307 let test_vector = &[
312 (PostfixKind::Println, "{}", r#"println!("{}", $0)"#), 308 (PostfixKind::Println, "{}", r#"println!("{}", $1)"#),
313 ( 309 (
314 PostfixKind::LogInfo, 310 PostfixKind::LogInfo,
315 "{} {expr} {} {2 + 2}", 311 "{} {expr} {} {2 + 2}",
316 r#"log::info!("{} {} {} {}", $0, expr, $1, 2 + 2)"#, 312 r#"log::info!("{} {} {} {}", $1, expr, $2, 2 + 2)"#,
317 ), 313 ),
318 (PostfixKind::Format, "{expr:?}", r#"format!("{:?}", expr)"#), 314 (PostfixKind::Format, "{expr:?}", r#"format!("{:?}", expr)"#),
319 ]; 315 ];