From 054c53aeb9a9e29d1c06fa183da263037aa62572 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 30 Sep 2019 09:56:20 +0300 Subject: move remove bounds to ast/edit.rs --- crates/ra_assists/src/assists/move_bounds.rs | 3 +-- crates/ra_assists/src/ast_editor.rs | 15 --------------- crates/ra_syntax/src/ast/edit.rs | 16 +++++++++++++++- 3 files changed, 16 insertions(+), 18 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/assists/move_bounds.rs b/crates/ra_assists/src/assists/move_bounds.rs index fd4bdc55c..1d27832a3 100644 --- a/crates/ra_assists/src/assists/move_bounds.rs +++ b/crates/ra_assists/src/assists/move_bounds.rs @@ -39,8 +39,7 @@ pub(crate) fn move_bounds_to_where_clause(mut ctx: AssistCtx) .type_params() .filter(|it| it.type_bound_list().is_some()) .map(|type_param| { - let without_bounds = - AstEditor::new(type_param.clone()).remove_bounds().ast().clone(); + let without_bounds = type_param.remove_bounds(); (type_param, without_bounds) }); diff --git a/crates/ra_assists/src/ast_editor.rs b/crates/ra_assists/src/ast_editor.rs index 54849b7b0..69abf28a1 100644 --- a/crates/ra_assists/src/ast_editor.rs +++ b/crates/ra_assists/src/ast_editor.rs @@ -51,18 +51,3 @@ impl AstEditor { N::cast(new_syntax).unwrap() } } - -impl AstEditor { - pub fn remove_bounds(&mut self) -> &mut Self { - let colon = match self.ast.colon_token() { - Some(it) => it, - None => return self, - }; - let end = match self.ast.type_bound_list() { - Some(it) => it.syntax().clone().into(), - None => colon.clone().into(), - }; - self.ast = self.replace_children(RangeInclusive::new(colon.into(), end), iter::empty()); - self - } -} diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 6e64c0675..9d0fd1383 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs @@ -10,7 +10,7 @@ use crate::{ ast::{ self, make::{self, tokens}, - AstNode, + AstNode, TypeBoundsOwner, }, AstToken, Direction, InsertPosition, SmolStr, SyntaxElement, SyntaxKind::{ATTR, COMMENT, WHITESPACE}, @@ -185,6 +185,20 @@ impl ast::RecordFieldList { } } +impl ast::TypeParam { + pub fn remove_bounds(&self) -> ast::TypeParam { + let colon = match self.colon_token() { + Some(it) => it, + None => return self.clone(), + }; + let end = match self.type_bound_list() { + Some(it) => it.syntax().clone().into(), + None => colon.clone().into(), + }; + replace_children(self, RangeInclusive::new(colon.into(), end), iter::empty()) + } +} + pub fn strip_attrs_and_docs(node: N) -> N { N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap() } -- cgit v1.2.3