From cd3d654f60dad121fb44dc7f2874003ee6f73a55 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Sat, 12 Sep 2020 18:09:00 +0300 Subject: Simplify is_string_literal function --- crates/ide/src/completion/complete_postfix/format_like.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'crates/ide/src/completion') 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 { if item.len() < 2 { return false; } - if item.chars().nth(0) != Some('"') || item.chars().nth(item.len() - 1) != Some('"') { - return false; - } - - true + item.starts_with("\"") && item.ends_with("\"") } /// Parser for a format-like string. It is more allowing in terms of string contents, @@ -269,8 +265,8 @@ mod tests { ("{correct}}}", Some(("{}}}", vec!["correct"]))), ("{correct}}}}}", Some(("{}}}}}", vec!["correct"]))), ("{incorrect}}", None), - ("placeholders {} {}", Some(("placeholders {} {}", vec!["$0", "$1"]))), - ("mixed {} {2 + 2} {}", Some(("mixed {} {} {}", vec!["$0", "2 + 2", "$1"]))), + ("placeholders {} {}", Some(("placeholders {} {}", vec!["$1", "$2"]))), + ("mixed {} {2 + 2} {}", Some(("mixed {} {} {}", vec!["$1", "2 + 2", "$2"]))), ( "{SomeStruct { val_a: 0, val_b: 1 }}", Some(("{}", vec!["SomeStruct { val_a: 0, val_b: 1 }"])), @@ -309,11 +305,11 @@ mod tests { #[test] fn test_into_suggestion() { let test_vector = &[ - (PostfixKind::Println, "{}", r#"println!("{}", $0)"#), + (PostfixKind::Println, "{}", r#"println!("{}", $1)"#), ( PostfixKind::LogInfo, "{} {expr} {} {2 + 2}", - r#"log::info!("{} {} {} {}", $0, expr, $1, 2 + 2)"#, + r#"log::info!("{} {} {} {}", $1, expr, $2, 2 + 2)"#, ), (PostfixKind::Format, "{expr:?}", r#"format!("{:?}", expr)"#), ]; -- cgit v1.2.3