diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-11 17:30:53 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-11 17:30:53 +0000 |
commit | b356ab46f2b7482bf1ae0c0f6cd5a87ece8742bf (patch) | |
tree | 094055dc8b24154fb8525c5910ae6dde4b4f4fe9 /crates/ra_assists/src/fill_match_arms.rs | |
parent | 77ccac74f94fbe387fc587d46f9d93f04fce3644 (diff) | |
parent | 5c9c0d3ae2735b4b32a44742bac800ca616fdde8 (diff) |
Merge #781
781: Refactor to allow for multiple assists r=matklad a=eulerdisk
This is necessary to allow assist "providers" (which currently are simple free function) to produce multiple assists. I'm not sure this is the best possible refactoring tough.
Co-authored-by: Andrea Pretto <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/fill_match_arms.rs')
-rw-r--r-- | crates/ra_assists/src/fill_match_arms.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/crates/ra_assists/src/fill_match_arms.rs b/crates/ra_assists/src/fill_match_arms.rs index 69b535a27..d8e40b4b7 100644 --- a/crates/ra_assists/src/fill_match_arms.rs +++ b/crates/ra_assists/src/fill_match_arms.rs | |||
@@ -8,7 +8,7 @@ use ra_syntax::ast::{self, AstNode}; | |||
8 | 8 | ||
9 | use crate::{AssistCtx, Assist}; | 9 | use crate::{AssistCtx, Assist}; |
10 | 10 | ||
11 | pub(crate) fn fill_match_arms(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 11 | pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
12 | let match_expr = ctx.node_at_offset::<ast::MatchExpr>()?; | 12 | let match_expr = ctx.node_at_offset::<ast::MatchExpr>()?; |
13 | 13 | ||
14 | // We already have some match arms, so we don't provide any assists. | 14 | // We already have some match arms, so we don't provide any assists. |
@@ -33,7 +33,7 @@ pub(crate) fn fill_match_arms(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist | |||
33 | let enum_name = enum_def.name(ctx.db)?; | 33 | let enum_name = enum_def.name(ctx.db)?; |
34 | let db = ctx.db; | 34 | let db = ctx.db; |
35 | 35 | ||
36 | ctx.build("fill match arms", |edit| { | 36 | ctx.add_action("fill match arms", |edit| { |
37 | let mut buf = format!("match {} {{\n", expr.syntax().text().to_string()); | 37 | let mut buf = format!("match {} {{\n", expr.syntax().text().to_string()); |
38 | let variants = enum_def.variants(db); | 38 | let variants = enum_def.variants(db); |
39 | for variant in variants { | 39 | for variant in variants { |
@@ -68,7 +68,9 @@ pub(crate) fn fill_match_arms(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist | |||
68 | edit.target(match_expr.syntax().range()); | 68 | edit.target(match_expr.syntax().range()); |
69 | edit.set_cursor(expr.syntax().range().start()); | 69 | edit.set_cursor(expr.syntax().range().start()); |
70 | edit.replace_node_and_indent(match_expr.syntax(), buf); | 70 | edit.replace_node_and_indent(match_expr.syntax(), buf); |
71 | }) | 71 | }); |
72 | |||
73 | ctx.build() | ||
72 | } | 74 | } |
73 | 75 | ||
74 | #[cfg(test)] | 76 | #[cfg(test)] |