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() .type_params()
.filter(|it| it.type_bound_list().is_some()) .filter(|it| it.type_bound_list().is_some())
.map(|type_param| { .map(|type_param| {
let without_bounds = let without_bounds = type_param.remove_bounds();
AstEditor::new(type_param.clone()).remove_bounds().ast().clone();
(type_param, without_bounds) (type_param, without_bounds)
}); });

View file

@ -51,18 +51,3 @@ impl<N: AstNode> AstEditor<N> {
N::cast(new_syntax).unwrap() 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::{ ast::{
self, self,
make::{self, tokens}, make::{self, tokens},
AstNode, AstNode, TypeBoundsOwner,
}, },
AstToken, Direction, InsertPosition, SmolStr, SyntaxElement, AstToken, Direction, InsertPosition, SmolStr, SyntaxElement,
SyntaxKind::{ATTR, COMMENT, WHITESPACE}, 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 { pub fn strip_attrs_and_docs<N: ast::AttrsOwner>(node: N) -> N {
N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap() N::cast(strip_attrs_and_docs_inner(node.syntax().clone())).unwrap()
} }