aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/assists
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-10-12 20:07:47 +0100
committerAleksey Kladov <[email protected]>2019-10-12 20:07:47 +0100
commitc00f298fd26d4982e9fe092ee004facf9cef6906 (patch)
tree6d66bed9aa538f34ea40b988af43774c16df909c /crates/ra_assists/src/assists
parent264a07975d23ad4d7cb41b309ba4a4c0a507a028 (diff)
add syntax-tree based indents
Diffstat (limited to 'crates/ra_assists/src/assists')
-rw-r--r--crates/ra_assists/src/assists/fill_match_arms.rs18
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 @@
3use std::iter; 3use std::iter;
4 4
5use hir::{db::HirDatabase, Adt, HasSource}; 5use hir::{db::HirDatabase, Adt, HasSource};
6use ra_syntax::ast::{self, make, AstNode, NameOwner}; 6use ra_syntax::ast::{self, edit::IndentLevel, make, AstNode, NameOwner};
7 7
8use crate::{Assist, AssistCtx, AssistId}; 8use 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()