Skip to content

Commit cd3d654

Browse files
committed
Simplify is_string_literal function
1 parent e447b3a commit cd3d654

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

crates/ide/src/completion/complete_postfix/format_like.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ fn is_string_literal(item: &str) -> bool {
5151
if item.len() < 2 {
5252
return false;
5353
}
54-
if item.chars().nth(0) != Some('"') || item.chars().nth(item.len() - 1) != Some('"') {
55-
return false;
56-
}
57-
58-
true
54+
item.starts_with("\"") && item.ends_with("\"")
5955
}
6056

6157
/// Parser for a format-like string. It is more allowing in terms of string contents,
@@ -269,8 +265,8 @@ mod tests {
269265
("{correct}}}", Some(("{}}}", vec!["correct"]))),
270266
("{correct}}}}}", Some(("{}}}}}", vec!["correct"]))),
271267
("{incorrect}}", None),
272-
("placeholders {} {}", Some(("placeholders {} {}", vec!["$0", "$1"]))),
273-
("mixed {} {2 + 2} {}", Some(("mixed {} {} {}", vec!["$0", "2 + 2", "$1"]))),
268+
("placeholders {} {}", Some(("placeholders {} {}", vec!["$1", "$2"]))),
269+
("mixed {} {2 + 2} {}", Some(("mixed {} {} {}", vec!["$1", "2 + 2", "$2"]))),
274270
(
275271
"{SomeStruct { val_a: 0, val_b: 1 }}",
276272
Some(("{}", vec!["SomeStruct { val_a: 0, val_b: 1 }"])),
@@ -309,11 +305,11 @@ mod tests {
309305
#[test]
310306
fn test_into_suggestion() {
311307
let test_vector = &[
312-
(PostfixKind::Println, "{}", r#"println!("{}", $0)"#),
308+
(PostfixKind::Println, "{}", r#"println!("{}", $1)"#),
313309
(
314310
PostfixKind::LogInfo,
315311
"{} {expr} {} {2 + 2}",
316-
r#"log::info!("{} {} {} {}", $0, expr, $1, 2 + 2)"#,
312+
r#"log::info!("{} {} {} {}", $1, expr, $2, 2 + 2)"#,
317313
),
318314
(PostfixKind::Format, "{expr:?}", r#"format!("{:?}", expr)"#),
319315
];

0 commit comments

Comments
 (0)