move remove bounds to ast/edit.rs

This commit is contained in:
Aleksey Kladov 2019-09-30 09:56:20 +03:00
parent e010b144d5
commit 054c53aeb9
3 changed files with 16 additions and 18 deletions

View File

@ -39,8 +39,7 @@ pub(crate) fn move_bounds_to_where_clause(mut ctx: AssistCtx<impl HirDatabase>)
.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)
});

View File

@ -51,18 +51,3 @@ impl<N: AstNode> AstEditor<N> {
N::cast(new_syntax).unwrap()
}
}
impl AstEditor<ast::TypeParam> {
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
}
}

View File

@ -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<N: ast::AttrsOwner>(node: N) -> N {
N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap()
}