Skip to content

Commit d143bf2

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

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

crates/assists/src/handlers/replace_string_with_char.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
use std::borrow::Cow;
2-
31
use syntax::{
4-
ast::{self, HasQuotes, HasStringValue},
2+
ast::{self, HasStringValue},
53
AstToken,
6-
SyntaxKind::{RAW_STRING, STRING},
7-
TextRange, TextSize,
4+
SyntaxKind::STRING,
85
};
9-
use test_utils::mark;
106

117
use crate::{AssistContext, AssistId, AssistKind, Assists};
128

@@ -29,7 +25,8 @@ pub(crate) fn replace_string_with_char(acc: &mut Assists, ctx: &AssistContext) -
2925
let token = ctx.find_token_at_offset(STRING).and_then(ast::String::cast)?;
3026
let value = token.value()?;
3127
let target = token.syntax().text_range();
32-
if value.len() > 1 || value.is_empty() {
28+
29+
if value.is_empty() || value.chars().count() > 1 {
3330
return None;
3431
}
3532

@@ -79,6 +76,23 @@ mod tests {
7976
)
8077
}
8178

79+
#[test]
80+
fn replace_string_with_char_assist_with_emoji() {
81+
check_assist(
82+
replace_string_with_char,
83+
r#"
84+
fn f() {
85+
let s = "<|>😀";
86+
}
87+
"#,
88+
r##"
89+
fn f() {
90+
let s = '😀';
91+
}
92+
"##,
93+
)
94+
}
95+
8296
#[test]
8397
fn replace_string_with_char_assist_not_applicable() {
8498
check_assist_not_applicable(

0 commit comments

Comments
 (0)