diff options
Diffstat (limited to 'crates/syntax/src/ast/edit_in_place.rs')
-rw-r--r-- | crates/syntax/src/ast/edit_in_place.rs | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs index b1eed0a2c..529bd0eb1 100644 --- a/crates/syntax/src/ast/edit_in_place.rs +++ b/crates/syntax/src/ast/edit_in_place.rs | |||
@@ -2,13 +2,13 @@ | |||
2 | 2 | ||
3 | use std::iter::empty; | 3 | use std::iter::empty; |
4 | 4 | ||
5 | use ast::{edit::AstNodeEdit, make, GenericParamsOwner, WhereClause}; | ||
6 | use parser::T; | 5 | use parser::T; |
7 | 6 | ||
8 | use crate::{ | 7 | use crate::{ |
9 | ast, | 8 | algo::neighbor, |
9 | ast::{self, edit::AstNodeEdit, make, GenericParamsOwner, WhereClause}, | ||
10 | ted::{self, Position}, | 10 | ted::{self, Position}, |
11 | AstNode, Direction, | 11 | AstNode, AstToken, Direction, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | use super::NameOwner; | 14 | use super::NameOwner; |
@@ -126,3 +126,41 @@ impl ast::TypeBoundList { | |||
126 | } | 126 | } |
127 | } | 127 | } |
128 | } | 128 | } |
129 | |||
130 | impl ast::UseTree { | ||
131 | pub fn remove(&self) { | ||
132 | for &dir in [Direction::Next, Direction::Prev].iter() { | ||
133 | if let Some(next_use_tree) = neighbor(self, dir) { | ||
134 | let separators = self | ||
135 | .syntax() | ||
136 | .siblings_with_tokens(dir) | ||
137 | .skip(1) | ||
138 | .take_while(|it| it.as_node() != Some(next_use_tree.syntax())); | ||
139 | ted::remove_all_iter(separators); | ||
140 | break; | ||
141 | } | ||
142 | } | ||
143 | ted::remove(self.syntax()) | ||
144 | } | ||
145 | } | ||
146 | |||
147 | impl ast::Use { | ||
148 | pub fn remove(&self) { | ||
149 | let next_ws = self | ||
150 | .syntax() | ||
151 | .next_sibling_or_token() | ||
152 | .and_then(|it| it.into_token()) | ||
153 | .and_then(ast::Whitespace::cast); | ||
154 | if let Some(next_ws) = next_ws { | ||
155 | let ws_text = next_ws.syntax().text(); | ||
156 | if let Some(rest) = ws_text.strip_prefix('\n') { | ||
157 | if rest.is_empty() { | ||
158 | ted::remove(next_ws.syntax()) | ||
159 | } else { | ||
160 | ted::replace(next_ws.syntax(), make::tokens::whitespace(rest)) | ||
161 | } | ||
162 | } | ||
163 | } | ||
164 | ted::remove(self.syntax()) | ||
165 | } | ||
166 | } | ||