mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-25 17:28:17 +00:00
internal: Migrate remove_mut assist to SyntaxEditor
This commit is contained in:
parent
b4f2d62952
commit
daca6b88c4
1 changed files with 8 additions and 7 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use syntax::{SyntaxKind, TextRange, T};
|
use syntax::{SyntaxKind, T};
|
||||||
|
|
||||||
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||||
|
|
||||||
|
|
@ -19,11 +19,6 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
|
||||||
// ```
|
// ```
|
||||||
pub(crate) fn remove_mut(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
pub(crate) fn remove_mut(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
|
||||||
let mut_token = ctx.find_token_syntax_at_offset(T![mut])?;
|
let mut_token = ctx.find_token_syntax_at_offset(T![mut])?;
|
||||||
let delete_from = mut_token.text_range().start();
|
|
||||||
let delete_to = match mut_token.next_token() {
|
|
||||||
Some(it) if it.kind() == SyntaxKind::WHITESPACE => it.text_range().end(),
|
|
||||||
_ => mut_token.text_range().end(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let target = mut_token.text_range();
|
let target = mut_token.text_range();
|
||||||
acc.add(
|
acc.add(
|
||||||
|
|
@ -31,7 +26,13 @@ pub(crate) fn remove_mut(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
|
||||||
"Remove `mut` keyword",
|
"Remove `mut` keyword",
|
||||||
target,
|
target,
|
||||||
|builder| {
|
|builder| {
|
||||||
builder.delete(TextRange::new(delete_from, delete_to));
|
let mut editor = builder.make_editor(&mut_token.parent().unwrap());
|
||||||
|
match mut_token.next_token() {
|
||||||
|
Some(it) if it.kind() == SyntaxKind::WHITESPACE => editor.delete(it),
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
editor.delete(mut_token);
|
||||||
|
builder.add_file_edits(ctx.file_id(), editor);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue