diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-10-12 20:08:27 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-10-12 20:08:27 +0100 |
commit | 77f2dd96a122e59a8d8df8afb53a741df9b1af76 (patch) | |
tree | 6d66bed9aa538f34ea40b988af43774c16df909c /crates/ra_assists/src/assists | |
parent | 264a07975d23ad4d7cb41b309ba4a4c0a507a028 (diff) | |
parent | c00f298fd26d4982e9fe092ee004facf9cef6906 (diff) |
Merge #2005
2005: add syntax-tree based indents r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/assists')
-rw-r--r-- | crates/ra_assists/src/assists/fill_match_arms.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/crates/ra_assists/src/assists/fill_match_arms.rs b/crates/ra_assists/src/assists/fill_match_arms.rs index 7335cce09..e3f30b5de 100644 --- a/crates/ra_assists/src/assists/fill_match_arms.rs +++ b/crates/ra_assists/src/assists/fill_match_arms.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | use std::iter; | 3 | use std::iter; |
4 | 4 | ||
5 | use hir::{db::HirDatabase, Adt, HasSource}; | 5 | use hir::{db::HirDatabase, Adt, HasSource}; |
6 | use ra_syntax::ast::{self, make, AstNode, NameOwner}; | 6 | use ra_syntax::ast::{self, edit::IndentLevel, make, AstNode, NameOwner}; |
7 | 7 | ||
8 | use crate::{Assist, AssistCtx, AssistId}; | 8 | use crate::{Assist, AssistCtx, AssistId}; |
9 | 9 | ||
@@ -30,15 +30,19 @@ pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<As | |||
30 | let variant_list = enum_def.variant_list()?; | 30 | let variant_list = enum_def.variant_list()?; |
31 | 31 | ||
32 | ctx.add_action(AssistId("fill_match_arms"), "fill match arms", |edit| { | 32 | ctx.add_action(AssistId("fill_match_arms"), "fill match arms", |edit| { |
33 | let variants = variant_list.variants(); | 33 | let indent_level = IndentLevel::from_node(match_arm_list.syntax()); |
34 | let arms = variants | 34 | |
35 | .filter_map(build_pat) | 35 | let new_arm_list = { |
36 | .map(|pat| make::match_arm(iter::once(pat), make::expr_unit())); | 36 | let variants = variant_list.variants(); |
37 | let new_arm_list = make::match_arm_list(arms); | 37 | let arms = variants |
38 | .filter_map(build_pat) | ||
39 | .map(|pat| make::match_arm(iter::once(pat), make::expr_unit())); | ||
40 | indent_level.increase_indent(make::match_arm_list(arms)) | ||
41 | }; | ||
38 | 42 | ||
39 | edit.target(match_expr.syntax().text_range()); | 43 | edit.target(match_expr.syntax().text_range()); |
40 | edit.set_cursor(expr.syntax().text_range().start()); | 44 | edit.set_cursor(expr.syntax().text_range().start()); |
41 | edit.replace_node_and_indent(match_arm_list.syntax(), new_arm_list.syntax().text()); | 45 | edit.replace_ast(match_arm_list, new_arm_list); |
42 | }); | 46 | }); |
43 | 47 | ||
44 | ctx.build() | 48 | ctx.build() |