diff options
-rw-r--r-- | crates/ra_assists/src/assists/add_explicit_type.rs | 2 | ||||
-rw-r--r-- | crates/ra_assists/src/assists/add_impl.rs | 2 | ||||
-rw-r--r-- | crates/ra_assists/src/assists/add_missing_impl_members.rs | 6 | ||||
-rw-r--r-- | crates/ra_assists/src/assists/early_return.rs | 2 | ||||
-rw-r--r-- | crates/ra_assists/src/assists/flip_binexpr.rs | 18 | ||||
-rw-r--r-- | crates/ra_assists/src/assists/flip_comma.rs | 17 | ||||
-rw-r--r-- | crates/ra_assists/src/assists/inline_local_variable.rs | 18 | ||||
-rw-r--r-- | crates/ra_assists/src/doc_tests/generated.rs | 52 | ||||
-rw-r--r-- | docs/user/assists.md | 57 | ||||
-rw-r--r-- | xtask/src/codegen/gen_assists_docs.rs | 6 |
10 files changed, 165 insertions, 15 deletions
diff --git a/crates/ra_assists/src/assists/add_explicit_type.rs b/crates/ra_assists/src/assists/add_explicit_type.rs index 302b95579..2903c1781 100644 --- a/crates/ra_assists/src/assists/add_explicit_type.rs +++ b/crates/ra_assists/src/assists/add_explicit_type.rs | |||
@@ -8,7 +8,7 @@ use crate::{Assist, AssistCtx, AssistId}; | |||
8 | 8 | ||
9 | // Assist: add_explicit_type | 9 | // Assist: add_explicit_type |
10 | // | 10 | // |
11 | // Specify type for a let binding | 11 | // Specify type for a let binding. |
12 | // | 12 | // |
13 | // ``` | 13 | // ``` |
14 | // fn main() { | 14 | // fn main() { |
diff --git a/crates/ra_assists/src/assists/add_impl.rs b/crates/ra_assists/src/assists/add_impl.rs index 43aeac7bd..142777b06 100644 --- a/crates/ra_assists/src/assists/add_impl.rs +++ b/crates/ra_assists/src/assists/add_impl.rs | |||
@@ -10,7 +10,7 @@ use crate::{Assist, AssistCtx, AssistId}; | |||
10 | 10 | ||
11 | // Assist: add_impl | 11 | // Assist: add_impl |
12 | // | 12 | // |
13 | // Adds a new inherent impl for a type | 13 | // Adds a new inherent impl for a type. |
14 | // | 14 | // |
15 | // ``` | 15 | // ``` |
16 | // struct Ctx<T: Clone> { | 16 | // struct Ctx<T: Clone> { |
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 fe1f2e72e..4ee4d47fa 100644 --- a/crates/ra_assists/src/assists/add_missing_impl_members.rs +++ b/crates/ra_assists/src/assists/add_missing_impl_members.rs | |||
@@ -14,7 +14,7 @@ enum AddMissingImplMembersMode { | |||
14 | 14 | ||
15 | // Assist: add_impl_missing_members | 15 | // Assist: add_impl_missing_members |
16 | // | 16 | // |
17 | // Adds scaffold for required impl members | 17 | // Adds scaffold for required impl members. |
18 | // | 18 | // |
19 | // ``` | 19 | // ``` |
20 | // trait T { | 20 | // trait T { |
@@ -50,7 +50,9 @@ pub(crate) fn add_missing_impl_members(ctx: AssistCtx<impl HirDatabase>) -> Opti | |||
50 | } | 50 | } |
51 | 51 | ||
52 | // Assist: add_impl_default_members | 52 | // Assist: add_impl_default_members |
53 | // Adds scaffold for overriding default impl members | 53 | // |
54 | // Adds scaffold for overriding default impl members. | ||
55 | // | ||
54 | // ``` | 56 | // ``` |
55 | // trait T { | 57 | // trait T { |
56 | // Type X; | 58 | // Type X; |
diff --git a/crates/ra_assists/src/assists/early_return.rs b/crates/ra_assists/src/assists/early_return.rs index b3d025340..48782db42 100644 --- a/crates/ra_assists/src/assists/early_return.rs +++ b/crates/ra_assists/src/assists/early_return.rs | |||
@@ -14,7 +14,9 @@ use crate::{ | |||
14 | }; | 14 | }; |
15 | 15 | ||
16 | // Assist: convert_to_guarded_return | 16 | // Assist: convert_to_guarded_return |
17 | // | ||
17 | // Replace a large conditional with a guarded return. | 18 | // Replace a large conditional with a guarded return. |
19 | // | ||
18 | // ``` | 20 | // ``` |
19 | // fn main() { | 21 | // fn main() { |
20 | // <|>if cond { | 22 | // <|>if cond { |
diff --git a/crates/ra_assists/src/assists/flip_binexpr.rs b/crates/ra_assists/src/assists/flip_binexpr.rs index c51035282..3a1e5cbe1 100644 --- a/crates/ra_assists/src/assists/flip_binexpr.rs +++ b/crates/ra_assists/src/assists/flip_binexpr.rs | |||
@@ -1,11 +1,23 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use hir::db::HirDatabase; | 1 | use hir::db::HirDatabase; |
4 | use ra_syntax::ast::{AstNode, BinExpr, BinOp}; | 2 | use ra_syntax::ast::{AstNode, BinExpr, BinOp}; |
5 | 3 | ||
6 | use crate::{Assist, AssistCtx, AssistId}; | 4 | use crate::{Assist, AssistCtx, AssistId}; |
7 | 5 | ||
8 | /// Flip binary expression assist. | 6 | // Assist: flip_binexpr |
7 | // | ||
8 | // Flips operands of a binary expression. | ||
9 | // | ||
10 | // ``` | ||
11 | // fn main() { | ||
12 | // let _ = 90 +<|> 2; | ||
13 | // } | ||
14 | // ``` | ||
15 | // -> | ||
16 | // ``` | ||
17 | // fn main() { | ||
18 | // let _ = 2 + 90; | ||
19 | // } | ||
20 | // ``` | ||
9 | pub(crate) fn flip_binexpr(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 21 | pub(crate) fn flip_binexpr(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
10 | let expr = ctx.node_at_offset::<BinExpr>()?; | 22 | let expr = ctx.node_at_offset::<BinExpr>()?; |
11 | let lhs = expr.lhs()?.syntax().clone(); | 23 | let lhs = expr.lhs()?.syntax().clone(); |
diff --git a/crates/ra_assists/src/assists/flip_comma.rs b/crates/ra_assists/src/assists/flip_comma.rs index e31cc5e7d..d06c5a0e1 100644 --- a/crates/ra_assists/src/assists/flip_comma.rs +++ b/crates/ra_assists/src/assists/flip_comma.rs | |||
@@ -1,10 +1,23 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use hir::db::HirDatabase; | 1 | use hir::db::HirDatabase; |
4 | use ra_syntax::{algo::non_trivia_sibling, Direction, T}; | 2 | use ra_syntax::{algo::non_trivia_sibling, Direction, T}; |
5 | 3 | ||
6 | use crate::{Assist, AssistCtx, AssistId}; | 4 | use crate::{Assist, AssistCtx, AssistId}; |
7 | 5 | ||
6 | // Assist: flip_comma | ||
7 | // | ||
8 | // Flips two comma-separated items. | ||
9 | // | ||
10 | // ``` | ||
11 | // fn main() { | ||
12 | // ((1, 2),<|> (3, 4)); | ||
13 | // } | ||
14 | // ``` | ||
15 | // -> | ||
16 | // ``` | ||
17 | // fn main() { | ||
18 | // ((3, 4), (1, 2)); | ||
19 | // } | ||
20 | // ``` | ||
8 | pub(crate) fn flip_comma(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 21 | pub(crate) fn flip_comma(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
9 | let comma = ctx.token_at_offset().find(|leaf| leaf.kind() == T![,])?; | 22 | let comma = ctx.token_at_offset().find(|leaf| leaf.kind() == T![,])?; |
10 | let prev = non_trivia_sibling(comma.clone().into(), Direction::Prev)?; | 23 | let prev = non_trivia_sibling(comma.clone().into(), Direction::Prev)?; |
diff --git a/crates/ra_assists/src/assists/inline_local_variable.rs b/crates/ra_assists/src/assists/inline_local_variable.rs index 9bd64decc..1997781db 100644 --- a/crates/ra_assists/src/assists/inline_local_variable.rs +++ b/crates/ra_assists/src/assists/inline_local_variable.rs | |||
@@ -1,5 +1,3 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use hir::db::HirDatabase; | 1 | use hir::db::HirDatabase; |
4 | use ra_syntax::{ | 2 | use ra_syntax::{ |
5 | ast::{self, AstNode, AstToken}, | 3 | ast::{self, AstNode, AstToken}, |
@@ -9,6 +7,22 @@ use ra_syntax::{ | |||
9 | use crate::assist_ctx::AssistBuilder; | 7 | use crate::assist_ctx::AssistBuilder; |
10 | use crate::{Assist, AssistCtx, AssistId}; | 8 | use crate::{Assist, AssistCtx, AssistId}; |
11 | 9 | ||
10 | // Assist: inline_local_variable | ||
11 | // | ||
12 | // Inlines local variable. | ||
13 | // | ||
14 | // ``` | ||
15 | // fn main() { | ||
16 | // let x<|> = 1 + 2; | ||
17 | // x * 4; | ||
18 | // } | ||
19 | // ``` | ||
20 | // -> | ||
21 | // ``` | ||
22 | // fn main() { | ||
23 | // (1 + 2) * 4; | ||
24 | // } | ||
25 | // ``` | ||
12 | pub(crate) fn inline_local_varialbe(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 26 | pub(crate) fn inline_local_varialbe(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
13 | let let_stmt = ctx.node_at_offset::<ast::LetStmt>()?; | 27 | let let_stmt = ctx.node_at_offset::<ast::LetStmt>()?; |
14 | let bind_pat = match let_stmt.pat()? { | 28 | let bind_pat = match let_stmt.pat()? { |
diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/doc_tests/generated.rs index 43fa159d7..d390db33c 100644 --- a/crates/ra_assists/src/doc_tests/generated.rs +++ b/crates/ra_assists/src/doc_tests/generated.rs | |||
@@ -203,3 +203,55 @@ fn handle(action: Action) { | |||
203 | "#####, | 203 | "#####, |
204 | ) | 204 | ) |
205 | } | 205 | } |
206 | |||
207 | #[test] | ||
208 | fn doctest_flip_binexpr() { | ||
209 | check( | ||
210 | "flip_binexpr", | ||
211 | r#####" | ||
212 | fn main() { | ||
213 | let _ = 90 +<|> 2; | ||
214 | } | ||
215 | "#####, | ||
216 | r#####" | ||
217 | fn main() { | ||
218 | let _ = 2 + 90; | ||
219 | } | ||
220 | "#####, | ||
221 | ) | ||
222 | } | ||
223 | |||
224 | #[test] | ||
225 | fn doctest_flip_comma() { | ||
226 | check( | ||
227 | "flip_comma", | ||
228 | r#####" | ||
229 | fn main() { | ||
230 | ((1, 2),<|> (3, 4)); | ||
231 | } | ||
232 | "#####, | ||
233 | r#####" | ||
234 | fn main() { | ||
235 | ((3, 4), (1, 2)); | ||
236 | } | ||
237 | "#####, | ||
238 | ) | ||
239 | } | ||
240 | |||
241 | #[test] | ||
242 | fn doctest_inline_local_variable() { | ||
243 | check( | ||
244 | "inline_local_variable", | ||
245 | r#####" | ||
246 | fn main() { | ||
247 | let x<|> = 1 + 2; | ||
248 | x * 4; | ||
249 | } | ||
250 | "#####, | ||
251 | r#####" | ||
252 | fn main() { | ||
253 | (1 + 2) * 4; | ||
254 | } | ||
255 | "#####, | ||
256 | ) | ||
257 | } | ||
diff --git a/docs/user/assists.md b/docs/user/assists.md index 603b29c66..8e2e8cc94 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md | |||
@@ -21,7 +21,7 @@ struct Point { | |||
21 | 21 | ||
22 | ## `add_explicit_type` | 22 | ## `add_explicit_type` |
23 | 23 | ||
24 | Specify type for a let binding | 24 | Specify type for a let binding. |
25 | 25 | ||
26 | ```rust | 26 | ```rust |
27 | // BEFORE | 27 | // BEFORE |
@@ -37,7 +37,7 @@ fn main() { | |||
37 | 37 | ||
38 | ## `add_impl` | 38 | ## `add_impl` |
39 | 39 | ||
40 | Adds a new inherent impl for a type | 40 | Adds a new inherent impl for a type. |
41 | 41 | ||
42 | ```rust | 42 | ```rust |
43 | // BEFORE | 43 | // BEFORE |
@@ -57,7 +57,7 @@ impl<T: Clone> Ctx<T> { | |||
57 | 57 | ||
58 | ## `add_impl_default_members` | 58 | ## `add_impl_default_members` |
59 | 59 | ||
60 | Adds scaffold for overriding default impl members | 60 | Adds scaffold for overriding default impl members. |
61 | 61 | ||
62 | ```rust | 62 | ```rust |
63 | // BEFORE | 63 | // BEFORE |
@@ -90,7 +90,7 @@ impl T for () { | |||
90 | 90 | ||
91 | ## `add_impl_missing_members` | 91 | ## `add_impl_missing_members` |
92 | 92 | ||
93 | Adds scaffold for required impl members | 93 | Adds scaffold for required impl members. |
94 | 94 | ||
95 | ```rust | 95 | ```rust |
96 | // BEFORE | 96 | // BEFORE |
@@ -196,3 +196,52 @@ fn handle(action: Action) { | |||
196 | } | 196 | } |
197 | } | 197 | } |
198 | ``` | 198 | ``` |
199 | |||
200 | ## `flip_binexpr` | ||
201 | |||
202 | Flips operands of a binary expression. | ||
203 | |||
204 | ```rust | ||
205 | // BEFORE | ||
206 | fn main() { | ||
207 | let _ = 90 +<|> 2; | ||
208 | } | ||
209 | |||
210 | // AFTER | ||
211 | fn main() { | ||
212 | let _ = 2 + 90; | ||
213 | } | ||
214 | ``` | ||
215 | |||
216 | ## `flip_comma` | ||
217 | |||
218 | Flips two comma-separated items. | ||
219 | |||
220 | ```rust | ||
221 | // BEFORE | ||
222 | fn main() { | ||
223 | ((1, 2),<|> (3, 4)); | ||
224 | } | ||
225 | |||
226 | // AFTER | ||
227 | fn main() { | ||
228 | ((3, 4), (1, 2)); | ||
229 | } | ||
230 | ``` | ||
231 | |||
232 | ## `inline_local_variable` | ||
233 | |||
234 | Inlines local variable. | ||
235 | |||
236 | ```rust | ||
237 | // BEFORE | ||
238 | fn main() { | ||
239 | let x<|> = 1 + 2; | ||
240 | x * 4; | ||
241 | } | ||
242 | |||
243 | // AFTER | ||
244 | fn main() { | ||
245 | (1 + 2) * 4; | ||
246 | } | ||
247 | ``` | ||
diff --git a/xtask/src/codegen/gen_assists_docs.rs b/xtask/src/codegen/gen_assists_docs.rs index 2ca7cda63..8dca2ed06 100644 --- a/xtask/src/codegen/gen_assists_docs.rs +++ b/xtask/src/codegen/gen_assists_docs.rs | |||
@@ -52,6 +52,12 @@ fn collect_assists() -> Result<Vec<Assist>> { | |||
52 | ); | 52 | ); |
53 | 53 | ||
54 | let doc = take_until(lines.by_ref(), "```").trim().to_string(); | 54 | let doc = take_until(lines.by_ref(), "```").trim().to_string(); |
55 | assert!( | ||
56 | doc.chars().next().unwrap().is_ascii_uppercase() && doc.ends_with("."), | ||
57 | "\n\n{}: assist docs should be proper sentences, with capitalization and a full stop at the end.\n\n{}\n\n", | ||
58 | id, doc, | ||
59 | ); | ||
60 | |||
55 | let before = take_until(lines.by_ref(), "```"); | 61 | let before = take_until(lines.by_ref(), "```"); |
56 | 62 | ||
57 | assert_eq!(lines.next().unwrap().as_str(), "->"); | 63 | assert_eq!(lines.next().unwrap().as_str(), "->"); |