diff options
Diffstat (limited to 'crates/ra_syntax/src/ast/edit.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/edit.rs | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 29eb3fcb9..abc7a646c 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs | |||
@@ -189,6 +189,21 @@ impl ast::RecordFieldList { | |||
189 | } | 189 | } |
190 | } | 190 | } |
191 | 191 | ||
192 | impl ast::TypeAliasDef { | ||
193 | #[must_use] | ||
194 | pub fn remove_bounds(&self) -> ast::TypeAliasDef { | ||
195 | let colon = match self.colon_token() { | ||
196 | Some(it) => it, | ||
197 | None => return self.clone(), | ||
198 | }; | ||
199 | let end = match self.type_bound_list() { | ||
200 | Some(it) => it.syntax().clone().into(), | ||
201 | None => colon.clone().into(), | ||
202 | }; | ||
203 | self.replace_children(colon.into()..=end, iter::empty()) | ||
204 | } | ||
205 | } | ||
206 | |||
192 | impl ast::TypeParam { | 207 | impl ast::TypeParam { |
193 | #[must_use] | 208 | #[must_use] |
194 | pub fn remove_bounds(&self) -> ast::TypeParam { | 209 | pub fn remove_bounds(&self) -> ast::TypeParam { |
@@ -299,12 +314,8 @@ impl ast::UseTree { | |||
299 | Some(it) => it, | 314 | Some(it) => it, |
300 | None => return self.clone(), | 315 | None => return self.clone(), |
301 | }; | 316 | }; |
302 | let use_tree = make::use_tree( | 317 | let use_tree = |
303 | suffix.clone(), | 318 | make::use_tree(suffix, self.use_tree_list(), self.alias(), self.star_token().is_some()); |
304 | self.use_tree_list(), | ||
305 | self.alias(), | ||
306 | self.star_token().is_some(), | ||
307 | ); | ||
308 | let nested = make::use_tree_list(iter::once(use_tree)); | 319 | let nested = make::use_tree_list(iter::once(use_tree)); |
309 | return make::use_tree(prefix.clone(), Some(nested), None, false); | 320 | return make::use_tree(prefix.clone(), Some(nested), None, false); |
310 | 321 | ||
@@ -579,12 +590,17 @@ pub trait AstNodeEdit: AstNode + Clone + Sized { | |||
579 | rewriter.rewrite_ast(self) | 590 | rewriter.rewrite_ast(self) |
580 | } | 591 | } |
581 | #[must_use] | 592 | #[must_use] |
582 | fn indent(&self, indent: IndentLevel) -> Self { | 593 | fn indent(&self, level: IndentLevel) -> Self { |
583 | Self::cast(indent.increase_indent(self.syntax().clone())).unwrap() | 594 | Self::cast(level.increase_indent(self.syntax().clone())).unwrap() |
595 | } | ||
596 | #[must_use] | ||
597 | fn dedent(&self, level: IndentLevel) -> Self { | ||
598 | Self::cast(level.decrease_indent(self.syntax().clone())).unwrap() | ||
584 | } | 599 | } |
585 | #[must_use] | 600 | #[must_use] |
586 | fn dedent(&self, indent: IndentLevel) -> Self { | 601 | fn reset_indent(&self) -> Self { |
587 | Self::cast(indent.decrease_indent(self.syntax().clone())).unwrap() | 602 | let level = IndentLevel::from_node(self.syntax()); |
603 | self.dedent(level) | ||
588 | } | 604 | } |
589 | } | 605 | } |
590 | 606 | ||