aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/doc_tests/generated.rs17
-rw-r--r--crates/ra_assists/src/handlers/remove_mut.rs32
-rw-r--r--crates/ra_assists/src/lib.rs2
3 files changed, 51 insertions, 0 deletions
diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/doc_tests/generated.rs
index 4ab09b167..3f56dd508 100644
--- a/crates/ra_assists/src/doc_tests/generated.rs
+++ b/crates/ra_assists/src/doc_tests/generated.rs
@@ -549,6 +549,23 @@ fn main() {
549} 549}
550 550
551#[test] 551#[test]
552fn doctest_remove_mut() {
553 check(
554 "remove_mut",
555 r#####"
556impl Walrus {
557 fn feed(&mut<|> self, amount: u32) {}
558}
559"#####,
560 r#####"
561impl Walrus {
562 fn feed(&self, amount: u32) {}
563}
564"#####,
565 )
566}
567
568#[test]
552fn doctest_replace_if_let_with_match() { 569fn doctest_replace_if_let_with_match() {
553 check( 570 check(
554 "replace_if_let_with_match", 571 "replace_if_let_with_match",
diff --git a/crates/ra_assists/src/handlers/remove_mut.rs b/crates/ra_assists/src/handlers/remove_mut.rs
new file mode 100644
index 000000000..6884830eb
--- /dev/null
+++ b/crates/ra_assists/src/handlers/remove_mut.rs
@@ -0,0 +1,32 @@
1use ra_syntax::{SyntaxKind, TextRange, T};
2
3use crate::{Assist, AssistCtx, AssistId};
4
5// Assist: remove_mut
6//
7// Removes the `mut` keyword.
8//
9// ```
10// impl Walrus {
11// fn feed(&mut<|> self, amount: u32) {}
12// }
13// ```
14// ->
15// ```
16// impl Walrus {
17// fn feed(&self, amount: u32) {}
18// }
19// ```
20pub(crate) fn remove_mut(ctx: AssistCtx) -> Option<Assist> {
21 let mut_token = ctx.find_token_at_offset(T![mut])?;
22 let delete_from = mut_token.text_range().start();
23 let delete_to = match mut_token.next_token() {
24 Some(it) if it.kind() == SyntaxKind::WHITESPACE => it.text_range().end(),
25 _ => mut_token.text_range().end(),
26 };
27
28 ctx.add_assist(AssistId("remove_mut"), "Remove `mut` keyword", |edit| {
29 edit.set_cursor(delete_from);
30 edit.delete(TextRange::from_to(delete_from, delete_to));
31 })
32}
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index f4a7497db..d7998b0d1 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -108,6 +108,7 @@ mod handlers {
108 mod introduce_variable; 108 mod introduce_variable;
109 mod inline_local_variable; 109 mod inline_local_variable;
110 mod raw_string; 110 mod raw_string;
111 mod remove_mut;
111 mod replace_if_let_with_match; 112 mod replace_if_let_with_match;
112 mod split_import; 113 mod split_import;
113 mod remove_dbg; 114 mod remove_dbg;
@@ -147,6 +148,7 @@ mod handlers {
147 raw_string::make_raw_string, 148 raw_string::make_raw_string,
148 raw_string::make_usual_string, 149 raw_string::make_usual_string,
149 raw_string::remove_hash, 150 raw_string::remove_hash,
151 remove_mut::remove_mut,
150 early_return::convert_to_guarded_return, 152 early_return::convert_to_guarded_return,
151 auto_import::auto_import, 153 auto_import::auto_import,
152 ] 154 ]