diff options
Diffstat (limited to 'crates/ra_assists')
-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 |
8 files changed, 106 insertions, 11 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 | } | ||