minor: move functionality to a better place

This commit is contained in:
Aleksey Kladov 2021-08-14 20:38:31 +03:00
parent 78c7940f5c
commit 3c49a9f079
4 changed files with 35 additions and 30 deletions

View file

@ -13,7 +13,9 @@ use crate::{
make, GenericParamsOwner,
},
ted::{self, Position},
AstNode, AstToken, Direction, SyntaxNode,
AstNode, AstToken, Direction,
SyntaxKind::{ATTR, COMMENT, WHITESPACE},
SyntaxNode,
};
use super::NameOwner;
@ -196,6 +198,32 @@ fn create_generic_param_list(position: Position) -> ast::GenericParamList {
gpl
}
pub trait AttrsOwnerEdit: ast::AttrsOwner + AstNodeEdit {
fn remove_attrs_and_docs(&self) {
remove_attrs_and_docs(self.syntax());
fn remove_attrs_and_docs(node: &SyntaxNode) {
let mut remove_next_ws = false;
for child in node.children_with_tokens() {
match child.kind() {
ATTR | COMMENT => {
remove_next_ws = true;
child.detach();
continue;
}
WHITESPACE if remove_next_ws => {
child.detach();
}
_ => (),
}
remove_next_ws = false;
}
}
}
}
impl<T: ast::AttrsOwner + AstNodeEdit> AttrsOwnerEdit for T {}
impl ast::GenericParamList {
pub fn add_generic_param(&self, generic_param: ast::GenericParam) {
match self.generic_params().last() {