aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/assists/change_visibility.rs13
-rw-r--r--crates/ra_assists/src/assists/fill_match_arms.rs24
-rw-r--r--crates/ra_assists/src/doc_tests/generated.rs39
3 files changed, 74 insertions, 2 deletions
diff --git a/crates/ra_assists/src/assists/change_visibility.rs b/crates/ra_assists/src/assists/change_visibility.rs
index df92c6b67..88118cdf7 100644
--- a/crates/ra_assists/src/assists/change_visibility.rs
+++ b/crates/ra_assists/src/assists/change_visibility.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, NameOwner, VisibilityOwner}, 3 ast::{self, NameOwner, VisibilityOwner},
@@ -13,6 +11,17 @@ use ra_syntax::{
13 11
14use crate::{Assist, AssistCtx, AssistId}; 12use crate::{Assist, AssistCtx, AssistId};
15 13
14// Assist: change_visibility
15//
16// Adds or changes existing visibility specifier.
17//
18// ```
19// fn<|> frobnicate() {}
20// ```
21// ->
22// ```
23// pub(crate) fn frobnicate() {}
24// ```
16pub(crate) fn change_visibility(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 25pub(crate) fn change_visibility(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
17 if let Some(vis) = ctx.node_at_offset::<ast::Visibility>() { 26 if let Some(vis) = ctx.node_at_offset::<ast::Visibility>() {
18 return change_vis(ctx, vis); 27 return change_vis(ctx, vis);
diff --git a/crates/ra_assists/src/assists/fill_match_arms.rs b/crates/ra_assists/src/assists/fill_match_arms.rs
index e3f30b5de..13b98d033 100644
--- a/crates/ra_assists/src/assists/fill_match_arms.rs
+++ b/crates/ra_assists/src/assists/fill_match_arms.rs
@@ -7,6 +7,30 @@ use ra_syntax::ast::{self, edit::IndentLevel, make, AstNode, NameOwner};
7 7
8use crate::{Assist, AssistCtx, AssistId}; 8use crate::{Assist, AssistCtx, AssistId};
9 9
10// Assist: fill_match_arms
11//
12// Adds missing clauses to a `match` expression.
13//
14// ```
15// enum Action { Move { distance: u32 }, Stop }
16//
17// fn handle(action: Action) {
18// match action {
19// <|>
20// }
21// }
22// ```
23// ->
24// ```
25// enum Action { Move { distance: u32 }, Stop }
26//
27// fn handle(action: Action) {
28// match action {
29// Action::Move{ distance } => (),
30// Action::Stop => (),
31// }
32// }
33// ```
10pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 34pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
11 let match_expr = ctx.node_at_offset::<ast::MatchExpr>()?; 35 let match_expr = ctx.node_at_offset::<ast::MatchExpr>()?;
12 let match_arm_list = match_expr.match_arm_list()?; 36 let match_arm_list = match_expr.match_arm_list()?;
diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/doc_tests/generated.rs
index 76d86b93d..2f36c3baa 100644
--- a/crates/ra_assists/src/doc_tests/generated.rs
+++ b/crates/ra_assists/src/doc_tests/generated.rs
@@ -142,6 +142,19 @@ fn main() {
142} 142}
143 143
144#[test] 144#[test]
145fn doctest_change_visibility() {
146 check(
147 "change_visibility",
148 r#####"
149fn<|> frobnicate() {}
150"#####,
151 r#####"
152pub(crate) fn frobnicate() {}
153"#####,
154 )
155}
156
157#[test]
145fn doctest_convert_to_guarded_return() { 158fn doctest_convert_to_guarded_return() {
146 check( 159 check(
147 "convert_to_guarded_return", 160 "convert_to_guarded_return",
@@ -164,3 +177,29 @@ fn main() {
164"#####, 177"#####,
165 ) 178 )
166} 179}
180
181#[test]
182fn doctest_fill_match_arms() {
183 check(
184 "fill_match_arms",
185 r#####"
186enum Action { Move { distance: u32 }, Stop }
187
188fn handle(action: Action) {
189 match action {
190 <|>
191 }
192}
193"#####,
194 r#####"
195enum Action { Move { distance: u32 }, Stop }
196
197fn handle(action: Action) {
198 match action {
199 Action::Move{ distance } => (),
200 Action::Stop => (),
201 }
202}
203"#####,
204 )
205}