aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/assists/add_derive.rs2
-rw-r--r--crates/ra_assists/src/assists/add_explicit_type.rs2
-rw-r--r--crates/ra_assists/src/assists/add_impl.rs2
-rw-r--r--crates/ra_assists/src/assists/add_missing_impl_members.rs2
-rw-r--r--crates/ra_assists/src/assists/apply_demorgan.rs2
-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
-rw-r--r--docs/user/assists.md37
-rw-r--r--docs/user/features.md51
-rw-r--r--xtask/src/codegen/gen_assists_docs.rs2
11 files changed, 122 insertions, 54 deletions
diff --git a/crates/ra_assists/src/assists/add_derive.rs b/crates/ra_assists/src/assists/add_derive.rs
index d3ba634c4..b077acb81 100644
--- a/crates/ra_assists/src/assists/add_derive.rs
+++ b/crates/ra_assists/src/assists/add_derive.rs
@@ -8,7 +8,9 @@ use ra_syntax::{
8use crate::{Assist, AssistCtx, AssistId}; 8use crate::{Assist, AssistCtx, AssistId};
9 9
10// Assist: add_derive 10// Assist: add_derive
11//
11// Adds a new `#[derive()]` clause to a struct or enum. 12// Adds a new `#[derive()]` clause to a struct or enum.
13//
12// ``` 14// ```
13// struct Point { 15// struct Point {
14// x: u32, 16// x: u32,
diff --git a/crates/ra_assists/src/assists/add_explicit_type.rs b/crates/ra_assists/src/assists/add_explicit_type.rs
index 33b7bea7f..302b95579 100644
--- a/crates/ra_assists/src/assists/add_explicit_type.rs
+++ b/crates/ra_assists/src/assists/add_explicit_type.rs
@@ -7,7 +7,9 @@ use ra_syntax::{
7use crate::{Assist, AssistCtx, AssistId}; 7use crate::{Assist, AssistCtx, AssistId};
8 8
9// Assist: add_explicit_type 9// Assist: add_explicit_type
10//
10// Specify type for a let binding 11// Specify type for a let binding
12//
11// ``` 13// ```
12// fn main() { 14// fn main() {
13// let x<|> = 92; 15// let x<|> = 92;
diff --git a/crates/ra_assists/src/assists/add_impl.rs b/crates/ra_assists/src/assists/add_impl.rs
index 40bc5c464..43aeac7bd 100644
--- a/crates/ra_assists/src/assists/add_impl.rs
+++ b/crates/ra_assists/src/assists/add_impl.rs
@@ -9,7 +9,9 @@ use ra_syntax::{
9use crate::{Assist, AssistCtx, AssistId}; 9use crate::{Assist, AssistCtx, AssistId};
10 10
11// Assist: add_impl 11// Assist: add_impl
12//
12// Adds a new inherent impl for a type 13// Adds a new inherent impl for a type
14//
13// ``` 15// ```
14// struct Ctx<T: Clone> { 16// struct Ctx<T: Clone> {
15// data: T,<|> 17// data: T,<|>
diff --git a/crates/ra_assists/src/assists/add_missing_impl_members.rs b/crates/ra_assists/src/assists/add_missing_impl_members.rs
index 36fa6f9ea..fe1f2e72e 100644
--- a/crates/ra_assists/src/assists/add_missing_impl_members.rs
+++ b/crates/ra_assists/src/assists/add_missing_impl_members.rs
@@ -13,7 +13,9 @@ enum AddMissingImplMembersMode {
13} 13}
14 14
15// Assist: add_impl_missing_members 15// Assist: add_impl_missing_members
16//
16// Adds scaffold for required impl members 17// Adds scaffold for required impl members
18//
17// ``` 19// ```
18// trait T { 20// trait T {
19// Type X; 21// Type X;
diff --git a/crates/ra_assists/src/assists/apply_demorgan.rs b/crates/ra_assists/src/assists/apply_demorgan.rs
index a072f63e7..75144cefe 100644
--- a/crates/ra_assists/src/assists/apply_demorgan.rs
+++ b/crates/ra_assists/src/assists/apply_demorgan.rs
@@ -5,11 +5,13 @@ use ra_syntax::SyntaxNode;
5use crate::{Assist, AssistCtx, AssistId}; 5use crate::{Assist, AssistCtx, AssistId};
6 6
7// Assist: apply_demorgan 7// Assist: apply_demorgan
8//
8// Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). 9// Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws).
9// This transforms expressions of the form `!l || !r` into `!(l && r)`. 10// This transforms expressions of the form `!l || !r` into `!(l && r)`.
10// This also works with `&&`. This assist can only be applied with the cursor 11// This also works with `&&`. This assist can only be applied with the cursor
11// on either `||` or `&&`, with both operands being a negation of some kind. 12// on either `||` or `&&`, with both operands being a negation of some kind.
12// This means something of the form `!x` or `x != y`. 13// This means something of the form `!x` or `x != y`.
14//
13// ``` 15// ```
14// fn main() { 16// fn main() {
15// if x != 4 ||<|> !y {} 17// if x != 4 ||<|> !y {}
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}
diff --git a/docs/user/assists.md b/docs/user/assists.md
index eeb486832..7a64c80ad 100644
--- a/docs/user/assists.md
+++ b/docs/user/assists.md
@@ -137,6 +137,18 @@ fn main() {
137} 137}
138``` 138```
139 139
140## `change_visibility`
141
142Adds or changes existing visibility specifier.
143
144```rust
145// BEFORE
146fn<|> frobnicate() {}
147
148// AFTER
149pub(crate) fn frobnicate() {}
150```
151
140## `convert_to_guarded_return` 152## `convert_to_guarded_return`
141 153
142Replace a large conditional with a guarded return. 154Replace a large conditional with a guarded return.
@@ -159,3 +171,28 @@ fn main() {
159 bar(); 171 bar();
160} 172}
161``` 173```
174
175## `fill_match_arms`
176
177Adds missing clauses to a `match` expression.
178
179```rust
180// BEFORE
181enum Action { Move { distance: u32 }, Stop }
182
183fn handle(action: Action) {
184 match action {
185 <|>
186 }
187}
188
189// AFTER
190enum Action { Move { distance: u32 }, Stop }
191
192fn handle(action: Action) {
193 match action {
194 Action::Move{ distance } => (),
195 Action::Stop => (),
196 }
197}
198```
diff --git a/docs/user/features.md b/docs/user/features.md
index acf092cec..39dab710d 100644
--- a/docs/user/features.md
+++ b/docs/user/features.md
@@ -118,57 +118,6 @@ impl Debug<|> for Foo {
118} 118}
119``` 119```
120 120
121- Change Visibility
122
123```rust
124// before:
125<|>fn foo() {}
126
127// after:
128<|>pub(crate) fn foo() {}
129
130// after:
131<|>pub fn foo() {}
132```
133
134- Fill match arms
135
136```rust
137// before:
138enum A {
139 As,
140 Bs,
141 Cs(String),
142 Ds(String, String),
143 Es{x: usize, y: usize}
144}
145
146fn main() {
147 let a = A::As;
148 match a<|> {}
149}
150
151// after:
152enum A {
153 As,
154 Bs,
155 Cs(String),
156 Ds(String, String),
157 Es{x: usize, y: usize}
158}
159
160fn main() {
161 let a = A::As;
162 match <|>a {
163 A::As => (),
164 A::Bs => (),
165 A::Cs(_) => (),
166 A::Ds(_, _) => (),
167 A::Es{x, y} => (),
168 }
169}
170```
171
172- Fill struct fields 121- Fill struct fields
173 122
174```rust 123```rust
diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs
index e313820d1..2ca7cda63 100644
--- a/xtask/src/codegen/gen_assists_docs.rs
+++ b/xtask/src/codegen/gen_assists_docs.rs
@@ -51,7 +51,7 @@ fn collect_assists() -> Result<Vec<Assist>> {
51 id 51 id
52 ); 52 );
53 53
54 let doc = take_until(lines.by_ref(), "```"); 54 let doc = take_until(lines.by_ref(), "```").trim().to_string();
55 let before = take_until(lines.by_ref(), "```"); 55 let before = take_until(lines.by_ref(), "```");
56 56
57 assert_eq!(lines.next().unwrap().as_str(), "->"); 57 assert_eq!(lines.next().unwrap().as_str(), "->");