mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Only replace quotes in replace_string_with_char assist
This commit is contained in:
parent
856c2850cd
commit
1a276f8959
@ -25,15 +25,16 @@ pub(crate) fn replace_string_with_char(acc: &mut Assists, ctx: &AssistContext) -
|
||||
if value.chars().take(2).count() != 1 {
|
||||
return None;
|
||||
}
|
||||
let quote_offets = token.quote_offsets()?;
|
||||
|
||||
acc.add(
|
||||
AssistId("replace_string_with_char", AssistKind::RefactorRewrite),
|
||||
"Replace string with char",
|
||||
target,
|
||||
|edit| {
|
||||
let token_text = token.syntax().text();
|
||||
let inner_text = &token_text[1..token_text.len() - 1];
|
||||
edit.replace(token.syntax().text_range(), format!("'{}'", inner_text));
|
||||
let (left, right) = quote_offets.quotes;
|
||||
edit.replace(left, String::from('\''));
|
||||
edit.replace(right, String::from('\''));
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -167,6 +168,23 @@ mod tests {
|
||||
fn f() {
|
||||
find('\u{7FFF}');
|
||||
}
|
||||
"##,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replace_raw_string_with_char() {
|
||||
check_assist(
|
||||
replace_string_with_char,
|
||||
r##"
|
||||
fn f() {
|
||||
$0r#"X"#
|
||||
}
|
||||
"##,
|
||||
r##"
|
||||
fn f() {
|
||||
'X'
|
||||
}
|
||||
"##,
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user