Assist: replace string with char
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
This commit is contained in:
parent
62192cede3
commit
c22c039578
@ -1,18 +1,14 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use syntax::{
|
||||
ast::{self, HasQuotes, HasStringValue},
|
||||
ast::{self, HasStringValue},
|
||||
AstToken,
|
||||
SyntaxKind::{RAW_STRING, STRING},
|
||||
TextRange, TextSize,
|
||||
SyntaxKind::STRING,
|
||||
};
|
||||
use test_utils::mark;
|
||||
|
||||
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||
|
||||
// Assist: replace_string_with_char
|
||||
//
|
||||
// Replace string with char
|
||||
// Replace string with char.
|
||||
//
|
||||
// ```
|
||||
// fn main() {
|
||||
@ -29,7 +25,8 @@ pub(crate) fn replace_string_with_char(acc: &mut Assists, ctx: &AssistContext) -
|
||||
let token = ctx.find_token_at_offset(STRING).and_then(ast::String::cast)?;
|
||||
let value = token.value()?;
|
||||
let target = token.syntax().text_range();
|
||||
if value.len() > 1 || value.is_empty() {
|
||||
|
||||
if value.is_empty() || value.chars().count() > 1 {
|
||||
return None;
|
||||
}
|
||||
|
||||
@ -79,6 +76,23 @@ mod tests {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replace_string_with_char_assist_with_emoji() {
|
||||
check_assist(
|
||||
replace_string_with_char,
|
||||
r#"
|
||||
fn f() {
|
||||
let s = "<|>😀";
|
||||
}
|
||||
"#,
|
||||
r##"
|
||||
fn f() {
|
||||
let s = '😀';
|
||||
}
|
||||
"##,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replace_string_with_char_assist_not_applicable() {
|
||||
check_assist_not_applicable(
|
||||
|
@ -881,6 +881,23 @@ fn process(map: HashMap<String, String>) {}
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn doctest_replace_string_with_char() {
|
||||
check_doc_test(
|
||||
"replace_string_with_char",
|
||||
r#####"
|
||||
fn main() {
|
||||
find("{<|>");
|
||||
}
|
||||
"#####,
|
||||
r#####"
|
||||
fn main() {
|
||||
find('{');
|
||||
}
|
||||
"#####,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn doctest_replace_unwrap_with_match() {
|
||||
check_doc_test(
|
||||
|
Loading…
x
Reference in New Issue
Block a user