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 | |
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')
-rw-r--r-- | crates/ra_assists/src/assist_ctx.rs | 1 | ||||
-rw-r--r-- | crates/ra_assists/src/assists/fill_match_arms.rs | 18 |
2 files changed, 12 insertions, 7 deletions
diff --git a/crates/ra_assists/src/assist_ctx.rs b/crates/ra_assists/src/assist_ctx.rs index 189cad7d0..e270c5d60 100644 --- a/crates/ra_assists/src/assist_ctx.rs +++ b/crates/ra_assists/src/assist_ctx.rs | |||
@@ -138,6 +138,7 @@ impl AssistBuilder { | |||
138 | 138 | ||
139 | /// Replaces specified `node` of text with a given string, reindenting the | 139 | /// Replaces specified `node` of text with a given string, reindenting the |
140 | /// string to maintain `node`'s existing indent. | 140 | /// string to maintain `node`'s existing indent. |
141 | // FIXME: remove in favor of ra_syntax::edit::IndentLevel::increase_indent | ||
141 | pub(crate) fn replace_node_and_indent( | 142 | pub(crate) fn replace_node_and_indent( |
142 | &mut self, | 143 | &mut self, |
143 | node: &SyntaxNode, | 144 | node: &SyntaxNode, |
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() |