diff options
Diffstat (limited to 'crates/syntax/src/ast/edit.rs')
-rw-r--r-- | crates/syntax/src/ast/edit.rs | 46 |
1 files changed, 8 insertions, 38 deletions
diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs index 347862b8a..18820786a 100644 --- a/crates/syntax/src/ast/edit.rs +++ b/crates/syntax/src/ast/edit.rs | |||
@@ -9,7 +9,7 @@ use std::{ | |||
9 | use arrayvec::ArrayVec; | 9 | use arrayvec::ArrayVec; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | algo::{self, neighbor, SyntaxRewriter}, | 12 | algo::{self, SyntaxRewriter}, |
13 | ast::{ | 13 | ast::{ |
14 | self, | 14 | self, |
15 | make::{self, tokens}, | 15 | make::{self, tokens}, |
@@ -322,27 +322,6 @@ impl ast::Use { | |||
322 | } | 322 | } |
323 | self.clone() | 323 | self.clone() |
324 | } | 324 | } |
325 | |||
326 | pub fn remove(&self) -> SyntaxRewriter<'static> { | ||
327 | let mut res = SyntaxRewriter::default(); | ||
328 | res.delete(self.syntax()); | ||
329 | let next_ws = self | ||
330 | .syntax() | ||
331 | .next_sibling_or_token() | ||
332 | .and_then(|it| it.into_token()) | ||
333 | .and_then(ast::Whitespace::cast); | ||
334 | if let Some(next_ws) = next_ws { | ||
335 | let ws_text = next_ws.syntax().text(); | ||
336 | if let Some(rest) = ws_text.strip_prefix('\n') { | ||
337 | if rest.is_empty() { | ||
338 | res.delete(next_ws.syntax()) | ||
339 | } else { | ||
340 | res.replace(next_ws.syntax(), &make::tokens::whitespace(rest)); | ||
341 | } | ||
342 | } | ||
343 | } | ||
344 | res | ||
345 | } | ||
346 | } | 325 | } |
347 | 326 | ||
348 | impl ast::UseTree { | 327 | impl ast::UseTree { |
@@ -396,22 +375,6 @@ impl ast::UseTree { | |||
396 | Some(res) | 375 | Some(res) |
397 | } | 376 | } |
398 | } | 377 | } |
399 | |||
400 | pub fn remove(&self) -> SyntaxRewriter<'static> { | ||
401 | let mut res = SyntaxRewriter::default(); | ||
402 | res.delete(self.syntax()); | ||
403 | for &dir in [Direction::Next, Direction::Prev].iter() { | ||
404 | if let Some(nb) = neighbor(self, dir) { | ||
405 | self.syntax() | ||
406 | .siblings_with_tokens(dir) | ||
407 | .skip(1) | ||
408 | .take_while(|it| it.as_node() != Some(nb.syntax())) | ||
409 | .for_each(|el| res.delete(&el)); | ||
410 | return res; | ||
411 | } | ||
412 | } | ||
413 | res | ||
414 | } | ||
415 | } | 378 | } |
416 | 379 | ||
417 | impl ast::MatchArmList { | 380 | impl ast::MatchArmList { |
@@ -592,6 +555,13 @@ impl ops::Add<u8> for IndentLevel { | |||
592 | } | 555 | } |
593 | 556 | ||
594 | impl IndentLevel { | 557 | impl IndentLevel { |
558 | pub fn from_element(element: &SyntaxElement) -> IndentLevel { | ||
559 | match element { | ||
560 | rowan::NodeOrToken::Node(it) => IndentLevel::from_node(it), | ||
561 | rowan::NodeOrToken::Token(it) => IndentLevel::from_token(it), | ||
562 | } | ||
563 | } | ||
564 | |||
595 | pub fn from_node(node: &SyntaxNode) -> IndentLevel { | 565 | pub fn from_node(node: &SyntaxNode) -> IndentLevel { |
596 | match node.first_token() { | 566 | match node.first_token() { |
597 | Some(it) => Self::from_token(&it), | 567 | Some(it) => Self::from_token(&it), |