mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-09 10:00:38 +00:00
minor: move functionality to a better place
This commit is contained in:
parent
78c7940f5c
commit
3c49a9f079
4 changed files with 35 additions and 30 deletions
|
@ -6,9 +6,7 @@ use std::{fmt, iter, ops};
|
|||
use crate::{
|
||||
algo,
|
||||
ast::{self, make, AstNode},
|
||||
ted, AstToken, NodeOrToken, SyntaxElement,
|
||||
SyntaxKind::{ATTR, COMMENT, WHITESPACE},
|
||||
SyntaxNode, SyntaxToken,
|
||||
ted, AstToken, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxToken,
|
||||
};
|
||||
|
||||
impl ast::UseTree {
|
||||
|
@ -48,28 +46,6 @@ impl ast::UseTree {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn remove_attrs_and_docs<N: ast::AttrsOwner>(node: &N) {
|
||||
remove_attrs_and_docs_inner(node.syntax())
|
||||
}
|
||||
|
||||
fn remove_attrs_and_docs_inner(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;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct IndentLevel(pub u8);
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue