Skip to content

Commit 4aa8609

Browse files
committed
Assist: replace string with char
Signed-off-by: Benjamin Coenen <[email protected]>
1 parent 62192ce commit 4aa8609

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

crates/assists/src/handlers/replace_string_with_char.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ pub(crate) fn replace_string_with_char(acc: &mut Assists, ctx: &AssistContext) -
2929
let token = ctx.find_token_at_offset(STRING).and_then(ast::String::cast)?;
3030
let value = token.value()?;
3131
let target = token.syntax().text_range();
32-
if value.len() > 1 || value.is_empty() {
32+
33+
if value.is_empty() || value.chars().count() > 1 {
3334
return None;
3435
}
3536

@@ -79,6 +80,23 @@ mod tests {
7980
)
8081
}
8182

83+
#[test]
84+
fn replace_string_with_char_assist_with_emoji() {
85+
check_assist(
86+
replace_string_with_char,
87+
r#"
88+
fn f() {
89+
let s = "<|>😀";
90+
}
91+
"#,
92+
r##"
93+
fn f() {
94+
let s = '😀';
95+
}
96+
"##,
97+
)
98+
}
99+
82100
#[test]
83101
fn replace_string_with_char_assist_not_applicable() {
84102
check_assist_not_applicable(

0 commit comments

Comments
 (0)