mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
rewrite merge use trees assist to use muatable syntax trees
changelog internal
This commit is contained in:
parent
d834306e7c
commit
9cbf09ec4f
7 changed files with 116 additions and 83 deletions
|
@ -2,13 +2,13 @@
|
|||
|
||||
use std::iter::empty;
|
||||
|
||||
use ast::{edit::AstNodeEdit, make, GenericParamsOwner, WhereClause};
|
||||
use parser::T;
|
||||
|
||||
use crate::{
|
||||
ast,
|
||||
algo::neighbor,
|
||||
ast::{self, edit::AstNodeEdit, make, GenericParamsOwner, WhereClause},
|
||||
ted::{self, Position},
|
||||
AstNode, Direction,
|
||||
AstNode, AstToken, Direction,
|
||||
};
|
||||
|
||||
use super::NameOwner;
|
||||
|
@ -126,3 +126,41 @@ impl ast::TypeBoundList {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::UseTree {
|
||||
pub fn remove(&self) {
|
||||
for &dir in [Direction::Next, Direction::Prev].iter() {
|
||||
if let Some(next_use_tree) = neighbor(self, dir) {
|
||||
let separators = self
|
||||
.syntax()
|
||||
.siblings_with_tokens(dir)
|
||||
.skip(1)
|
||||
.take_while(|it| it.as_node() != Some(next_use_tree.syntax()));
|
||||
ted::remove_all_iter(separators);
|
||||
break;
|
||||
}
|
||||
}
|
||||
ted::remove(self.syntax())
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::Use {
|
||||
pub fn remove(&self) {
|
||||
let next_ws = self
|
||||
.syntax()
|
||||
.next_sibling_or_token()
|
||||
.and_then(|it| it.into_token())
|
||||
.and_then(ast::Whitespace::cast);
|
||||
if let Some(next_ws) = next_ws {
|
||||
let ws_text = next_ws.syntax().text();
|
||||
if let Some(rest) = ws_text.strip_prefix('\n') {
|
||||
if rest.is_empty() {
|
||||
ted::remove(next_ws.syntax())
|
||||
} else {
|
||||
ted::replace(next_ws.syntax(), make::tokens::whitespace(rest))
|
||||
}
|
||||
}
|
||||
}
|
||||
ted::remove(self.syntax())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue