aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/assists
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-10-27 08:26:46 +0000
committerAleksey Kladov <[email protected]>2019-10-27 08:26:46 +0000
commita490ba06fa635ecb34b5ce0b7205621eefaee603 (patch)
tree3793da47dbe724189842cabeb5a7cef91ad592ef /crates/ra_assists/src/assists
parent85984b09e182adca4b03d9f7efab20d48b5b632a (diff)
document some more assists
Diffstat (limited to 'crates/ra_assists/src/assists')
-rw-r--r--crates/ra_assists/src/assists/merge_match_arms.rs26
-rw-r--r--crates/ra_assists/src/assists/move_bounds.rs17
-rw-r--r--crates/ra_assists/src/assists/move_guard.rs52
3 files changed, 89 insertions, 6 deletions
diff --git a/crates/ra_assists/src/assists/merge_match_arms.rs b/crates/ra_assists/src/assists/merge_match_arms.rs
index 17baa98f9..f5ddd7159 100644
--- a/crates/ra_assists/src/assists/merge_match_arms.rs
+++ b/crates/ra_assists/src/assists/merge_match_arms.rs
@@ -1,9 +1,31 @@
1//! FIXME: write short doc here
2
3use crate::{Assist, AssistCtx, AssistId, TextRange, TextUnit}; 1use crate::{Assist, AssistCtx, AssistId, TextRange, TextUnit};
4use hir::db::HirDatabase; 2use hir::db::HirDatabase;
5use ra_syntax::ast::{AstNode, MatchArm}; 3use ra_syntax::ast::{AstNode, MatchArm};
6 4
5// Assist: merge_match_arms
6//
7// Merges identical match arms.
8//
9// ```
10// enum Action { Move { distance: u32 }, Stop }
11//
12// fn handle(action: Action) {
13// match action {
14// <|>Action::Move(..) => foo(),
15// Action::Stop => foo(),
16// }
17// }
18// ```
19// ->
20// ```
21// enum Action { Move { distance: u32 }, Stop }
22//
23// fn handle(action: Action) {
24// match action {
25// Action::Move(..) | Action::Stop => foo(),
26// }
27// }
28// ```
7pub(crate) fn merge_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 29pub(crate) fn merge_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
8 let current_arm = ctx.node_at_offset::<MatchArm>()?; 30 let current_arm = ctx.node_at_offset::<MatchArm>()?;
9 31
diff --git a/crates/ra_assists/src/assists/move_bounds.rs b/crates/ra_assists/src/assists/move_bounds.rs
index d2444b6b9..f96e19a9f 100644
--- a/crates/ra_assists/src/assists/move_bounds.rs
+++ b/crates/ra_assists/src/assists/move_bounds.rs
@@ -1,5 +1,3 @@
1//! FIXME: write short doc here
2
3use hir::db::HirDatabase; 1use hir::db::HirDatabase;
4use ra_syntax::{ 2use ra_syntax::{
5 ast::{self, edit, make, AstNode, NameOwner, TypeBoundsOwner}, 3 ast::{self, edit, make, AstNode, NameOwner, TypeBoundsOwner},
@@ -9,6 +7,21 @@ use ra_syntax::{
9 7
10use crate::{Assist, AssistCtx, AssistId}; 8use crate::{Assist, AssistCtx, AssistId};
11 9
10// Assist: move_bounds_to_where_clause
11//
12// Moves inline type bounds to a where clause.
13//
14// ```
15// fn apply<T, U, <|>F: FnOnce(T) -> U>(f: F, x: T) -> U {
16// f(x)
17// }
18// ```
19// ->
20// ```
21// fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U {
22// f(x)
23// }
24// ```
12pub(crate) fn move_bounds_to_where_clause(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 25pub(crate) fn move_bounds_to_where_clause(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
13 let type_param_list = ctx.node_at_offset::<ast::TypeParamList>()?; 26 let type_param_list = ctx.node_at_offset::<ast::TypeParamList>()?;
14 27
diff --git a/crates/ra_assists/src/assists/move_guard.rs b/crates/ra_assists/src/assists/move_guard.rs
index 51aea6334..36c95128d 100644
--- a/crates/ra_assists/src/assists/move_guard.rs
+++ b/crates/ra_assists/src/assists/move_guard.rs
@@ -1,5 +1,3 @@
1//! FIXME: write short doc here
2
3use hir::db::HirDatabase; 1use hir::db::HirDatabase;
4use ra_syntax::{ 2use ra_syntax::{
5 ast, 3 ast,
@@ -9,6 +7,31 @@ use ra_syntax::{
9 7
10use crate::{Assist, AssistCtx, AssistId}; 8use crate::{Assist, AssistCtx, AssistId};
11 9
10// Assist: move_guard_to_arm_body
11//
12// Moves match guard into match arm body.
13//
14// ```
15// enum Action { Move { distance: u32 }, Stop }
16//
17// fn handle(action: Action) {
18// match action {
19// Action::Move { distance } <|>if distance > 10 => foo(),
20// _ => (),
21// }
22// }
23// ```
24// ->
25// ```
26// enum Action { Move { distance: u32 }, Stop }
27//
28// fn handle(action: Action) {
29// match action {
30// Action::Move { distance } => if distance > 10 { foo() },
31// _ => (),
32// }
33// }
34// ```
12pub(crate) fn move_guard_to_arm_body(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 35pub(crate) fn move_guard_to_arm_body(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
13 let match_arm = ctx.node_at_offset::<MatchArm>()?; 36 let match_arm = ctx.node_at_offset::<MatchArm>()?;
14 let guard = match_arm.guard()?; 37 let guard = match_arm.guard()?;
@@ -42,6 +65,31 @@ pub(crate) fn move_guard_to_arm_body(mut ctx: AssistCtx<impl HirDatabase>) -> Op
42 ctx.build() 65 ctx.build()
43} 66}
44 67
68// Assist: move_arm_cond_to_match_guard
69//
70// Moves if expression from match arm body into a guard.
71//
72// ```
73// enum Action { Move { distance: u32 }, Stop }
74//
75// fn handle(action: Action) {
76// match action {
77// Action::Move { distance } => <|>if distance > 10 { foo() },
78// _ => (),
79// }
80// }
81// ```
82// ->
83// ```
84// enum Action { Move { distance: u32 }, Stop }
85//
86// fn handle(action: Action) {
87// match action {
88// Action::Move { distance } if distance > 10 => foo(),
89// _ => (),
90// }
91// }
92// ```
45pub(crate) fn move_arm_cond_to_match_guard(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 93pub(crate) fn move_arm_cond_to_match_guard(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
46 let match_arm: MatchArm = ctx.node_at_offset::<MatchArm>()?; 94 let match_arm: MatchArm = ctx.node_at_offset::<MatchArm>()?;
47 let last_match_pat = match_arm.pats().last()?; 95 let last_match_pat = match_arm.pats().last()?;