@@ -3,13 +3,14 @@ use std::mem;
33use ra_syntax:: {
44 algo:: { find_covering_node, find_leaf_at_offset, LeafAtOffset } ,
55 ast,
6- text_utils:: { contains_offset_nonstrict , intersect} ,
6+ text_utils:: intersect,
77 AstNode , SourceFileNode , SyntaxKind ,
88 SyntaxKind :: * ,
99 SyntaxNodeRef , TextRange , TextUnit ,
1010} ;
11+ use ra_text_edit:: text_utils:: contains_offset_nonstrict;
1112
12- use crate :: { find_node_at_offset, EditBuilder , LocalEdit } ;
13+ use crate :: { find_node_at_offset, TextEditBuilder , LocalEdit } ;
1314
1415pub fn join_lines ( file : & SourceFileNode , range : TextRange ) -> LocalEdit {
1516 let range = if range. is_empty ( ) {
@@ -18,7 +19,7 @@ pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit {
1819 let pos = match text. find ( '\n' ) {
1920 None => {
2021 return LocalEdit {
21- edit : EditBuilder :: new ( ) . finish ( ) ,
22+ edit : TextEditBuilder :: new ( ) . finish ( ) ,
2223 cursor_position : None ,
2324 } ;
2425 }
@@ -30,7 +31,7 @@ pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit {
3031 } ;
3132
3233 let node = find_covering_node ( file. syntax ( ) , range) ;
33- let mut edit = EditBuilder :: new ( ) ;
34+ let mut edit = TextEditBuilder :: new ( ) ;
3435 for node in node. descendants ( ) {
3536 let text = match node. leaf_text ( ) {
3637 Some ( text) => text,
@@ -72,7 +73,7 @@ pub fn on_enter(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> {
7273 let indent = node_indent ( file, comment. syntax ( ) ) ?;
7374 let inserted = format ! ( "\n {}{} " , indent, prefix) ;
7475 let cursor_position = offset + TextUnit :: of_str ( & inserted) ;
75- let mut edit = EditBuilder :: new ( ) ;
76+ let mut edit = TextEditBuilder :: new ( ) ;
7677 edit. insert ( offset, inserted) ;
7778 Some ( LocalEdit {
7879 edit : edit. finish ( ) ,
@@ -122,15 +123,20 @@ pub fn on_eq_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit>
122123 return None ;
123124 }
124125 let offset = let_stmt. syntax ( ) . range ( ) . end ( ) ;
125- let mut edit = EditBuilder :: new ( ) ;
126+ let mut edit = TextEditBuilder :: new ( ) ;
126127 edit. insert ( offset, ";" . to_string ( ) ) ;
127128 Some ( LocalEdit {
128129 edit : edit. finish ( ) ,
129130 cursor_position : None ,
130131 } )
131132}
132133
133- fn remove_newline ( edit : & mut EditBuilder , node : SyntaxNodeRef , node_text : & str , offset : TextUnit ) {
134+ fn remove_newline (
135+ edit : & mut TextEditBuilder ,
136+ node : SyntaxNodeRef ,
137+ node_text : & str ,
138+ offset : TextUnit ,
139+ ) {
134140 if node. kind ( ) != WHITESPACE || node_text. bytes ( ) . filter ( |& b| b == b'\n' ) . count ( ) != 1 {
135141 // The node is either the first or the last in the file
136142 let suff = & node_text[ TextRange :: from_to (
@@ -191,7 +197,7 @@ fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool {
191197 }
192198}
193199
194- fn join_single_expr_block ( edit : & mut EditBuilder , node : SyntaxNodeRef ) -> Option < ( ) > {
200+ fn join_single_expr_block ( edit : & mut TextEditBuilder , node : SyntaxNodeRef ) -> Option < ( ) > {
195201 let block = ast:: Block :: cast ( node. parent ( ) ?) ?;
196202 let block_expr = ast:: BlockExpr :: cast ( block. syntax ( ) . parent ( ) ?) ?;
197203 let expr = single_expr ( block) ?;
@@ -269,14 +275,14 @@ fn foo() {
269275 fn test_join_lines_lambda_block ( ) {
270276 check_join_lines (
271277 r"
272- pub fn reparse(&self, edit: &AtomEdit ) -> File {
278+ pub fn reparse(&self, edit: &AtomTextEdit ) -> File {
273279 <|>self.incremental_reparse(edit).unwrap_or_else(|| {
274280 self.full_reparse(edit)
275281 })
276282}
277283" ,
278284 r"
279- pub fn reparse(&self, edit: &AtomEdit ) -> File {
285+ pub fn reparse(&self, edit: &AtomTextEdit ) -> File {
280286 <|>self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit))
281287}
282288" ,
0 commit comments