@@ -6,11 +6,7 @@ use parser::{SyntaxKind, T};
6
6
7
7
use crate :: {
8
8
algo:: { self , neighbor} ,
9
- ast:: {
10
- self , edit:: IndentLevel , make, syntax_factory:: SyntaxFactory , HasGenericArgs ,
11
- HasGenericParams ,
12
- } ,
13
- syntax_editor:: SyntaxEditor ,
9
+ ast:: { self , edit:: IndentLevel , make, HasGenericArgs , HasGenericParams } ,
14
10
ted:: { self , Position } ,
15
11
AstNode , AstToken , Direction , SyntaxElement ,
16
12
SyntaxKind :: { ATTR , COMMENT , WHITESPACE } ,
@@ -389,10 +385,6 @@ pub trait Removable: AstNode {
389
385
fn remove ( & self ) ;
390
386
}
391
387
392
- pub trait EditorRemovable : AstNode {
393
- fn remove ( & self , editor : & mut SyntaxEditor ) ;
394
- }
395
-
396
388
impl Removable for ast:: TypeBoundList {
397
389
fn remove ( & self ) {
398
390
match self . syntax ( ) . siblings_with_tokens ( Direction :: Prev ) . find ( |it| it. kind ( ) == T ! [ : ] ) {
@@ -447,35 +439,16 @@ impl Removable for ast::UseTree {
447
439
}
448
440
}
449
441
450
- impl EditorRemovable for ast:: UseTree {
451
- fn remove ( & self , editor : & mut SyntaxEditor ) {
452
- for dir in [ Direction :: Next , Direction :: Prev ] {
453
- if let Some ( next_use_tree) = neighbor ( self , dir) {
454
- let separators = self
455
- . syntax ( )
456
- . siblings_with_tokens ( dir)
457
- . skip ( 1 )
458
- . take_while ( |it| it. as_node ( ) != Some ( next_use_tree. syntax ( ) ) ) ;
459
- for sep in separators {
460
- editor. delete ( sep) ;
461
- }
462
- break ;
463
- }
464
- }
465
- editor. delete ( self . syntax ( ) ) ;
466
- }
467
- }
468
-
469
442
impl ast:: UseTree {
470
443
/// Deletes the usetree node represented by the input. Recursively removes parents, including use nodes that become empty.
471
444
pub fn remove_recursive ( self ) {
472
445
let parent = self . syntax ( ) . parent ( ) ;
473
446
474
- Removable :: remove ( & self ) ;
447
+ self . remove ( ) ;
475
448
476
449
if let Some ( u) = parent. clone ( ) . and_then ( ast:: Use :: cast) {
477
450
if u. use_tree ( ) . is_none ( ) {
478
- Removable :: remove ( & u ) ;
451
+ u . remove ( )
479
452
}
480
453
} else if let Some ( u) = parent. and_then ( ast:: UseTreeList :: cast) {
481
454
if u. use_trees ( ) . next ( ) . is_none ( ) {
@@ -643,45 +616,6 @@ impl Removable for ast::Use {
643
616
}
644
617
}
645
618
646
- impl EditorRemovable for ast:: Use {
647
- fn remove ( & self , editor : & mut SyntaxEditor ) {
648
- let make = SyntaxFactory :: new ( ) ;
649
-
650
- let next_ws = self
651
- . syntax ( )
652
- . next_sibling_or_token ( )
653
- . and_then ( |it| it. into_token ( ) )
654
- . and_then ( ast:: Whitespace :: cast) ;
655
- if let Some ( next_ws) = next_ws {
656
- let ws_text = next_ws. syntax ( ) . text ( ) ;
657
- if let Some ( rest) = ws_text. strip_prefix ( '\n' ) {
658
- if rest. is_empty ( ) {
659
- editor. delete ( next_ws. syntax ( ) ) ;
660
- } else {
661
- editor. replace ( next_ws. syntax ( ) , make. whitespace ( rest) ) ;
662
- }
663
- }
664
- }
665
- let prev_ws = self
666
- . syntax ( )
667
- . prev_sibling_or_token ( )
668
- . and_then ( |it| it. into_token ( ) )
669
- . and_then ( ast:: Whitespace :: cast) ;
670
- if let Some ( prev_ws) = prev_ws {
671
- let ws_text = prev_ws. syntax ( ) . text ( ) ;
672
- let prev_newline = ws_text. rfind ( '\n' ) . map ( |x| x + 1 ) . unwrap_or ( 0 ) ;
673
- let rest = & ws_text[ 0 ..prev_newline] ;
674
- if rest. is_empty ( ) {
675
- editor. delete ( prev_ws. syntax ( ) ) ;
676
- } else {
677
- editor. replace ( prev_ws. syntax ( ) , make. whitespace ( rest) ) ;
678
- }
679
- }
680
-
681
- editor. delete ( self . syntax ( ) ) ;
682
- }
683
- }
684
-
685
619
impl ast:: Impl {
686
620
pub fn get_or_create_assoc_item_list ( & self ) -> ast:: AssocItemList {
687
621
if self . assoc_item_list ( ) . is_none ( ) {
0 commit comments