@@ -3,13 +3,14 @@ use std::mem;
3
3
use ra_syntax:: {
4
4
algo:: { find_covering_node, find_leaf_at_offset, LeafAtOffset } ,
5
5
ast,
6
- text_utils:: { contains_offset_nonstrict , intersect} ,
6
+ text_utils:: intersect,
7
7
AstNode , SourceFileNode , SyntaxKind ,
8
8
SyntaxKind :: * ,
9
9
SyntaxNodeRef , TextRange , TextUnit ,
10
10
} ;
11
+ use ra_text_edit:: text_utils:: contains_offset_nonstrict;
11
12
12
- use crate :: { find_node_at_offset, EditBuilder , LocalEdit } ;
13
+ use crate :: { find_node_at_offset, TextEditBuilder , LocalEdit } ;
13
14
14
15
pub fn join_lines ( file : & SourceFileNode , range : TextRange ) -> LocalEdit {
15
16
let range = if range. is_empty ( ) {
@@ -18,7 +19,7 @@ pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit {
18
19
let pos = match text. find ( '\n' ) {
19
20
None => {
20
21
return LocalEdit {
21
- edit : EditBuilder :: new ( ) . finish ( ) ,
22
+ edit : TextEditBuilder :: new ( ) . finish ( ) ,
22
23
cursor_position : None ,
23
24
} ;
24
25
}
@@ -30,7 +31,7 @@ pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit {
30
31
} ;
31
32
32
33
let node = find_covering_node ( file. syntax ( ) , range) ;
33
- let mut edit = EditBuilder :: new ( ) ;
34
+ let mut edit = TextEditBuilder :: new ( ) ;
34
35
for node in node. descendants ( ) {
35
36
let text = match node. leaf_text ( ) {
36
37
Some ( text) => text,
@@ -72,7 +73,7 @@ pub fn on_enter(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> {
72
73
let indent = node_indent ( file, comment. syntax ( ) ) ?;
73
74
let inserted = format ! ( "\n {}{} " , indent, prefix) ;
74
75
let cursor_position = offset + TextUnit :: of_str ( & inserted) ;
75
- let mut edit = EditBuilder :: new ( ) ;
76
+ let mut edit = TextEditBuilder :: new ( ) ;
76
77
edit. insert ( offset, inserted) ;
77
78
Some ( LocalEdit {
78
79
edit : edit. finish ( ) ,
@@ -122,15 +123,20 @@ pub fn on_eq_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit>
122
123
return None ;
123
124
}
124
125
let offset = let_stmt. syntax ( ) . range ( ) . end ( ) ;
125
- let mut edit = EditBuilder :: new ( ) ;
126
+ let mut edit = TextEditBuilder :: new ( ) ;
126
127
edit. insert ( offset, ";" . to_string ( ) ) ;
127
128
Some ( LocalEdit {
128
129
edit : edit. finish ( ) ,
129
130
cursor_position : None ,
130
131
} )
131
132
}
132
133
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
+ ) {
134
140
if node. kind ( ) != WHITESPACE || node_text. bytes ( ) . filter ( |& b| b == b'\n' ) . count ( ) != 1 {
135
141
// The node is either the first or the last in the file
136
142
let suff = & node_text[ TextRange :: from_to (
@@ -191,7 +197,7 @@ fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool {
191
197
}
192
198
}
193
199
194
- fn join_single_expr_block ( edit : & mut EditBuilder , node : SyntaxNodeRef ) -> Option < ( ) > {
200
+ fn join_single_expr_block ( edit : & mut TextEditBuilder , node : SyntaxNodeRef ) -> Option < ( ) > {
195
201
let block = ast:: Block :: cast ( node. parent ( ) ?) ?;
196
202
let block_expr = ast:: BlockExpr :: cast ( block. syntax ( ) . parent ( ) ?) ?;
197
203
let expr = single_expr ( block) ?;
@@ -269,14 +275,14 @@ fn foo() {
269
275
fn test_join_lines_lambda_block ( ) {
270
276
check_join_lines (
271
277
r"
272
- pub fn reparse(&self, edit: &AtomEdit ) -> File {
278
+ pub fn reparse(&self, edit: &AtomTextEdit ) -> File {
273
279
<|>self.incremental_reparse(edit).unwrap_or_else(|| {
274
280
self.full_reparse(edit)
275
281
})
276
282
}
277
283
" ,
278
284
r"
279
- pub fn reparse(&self, edit: &AtomEdit ) -> File {
285
+ pub fn reparse(&self, edit: &AtomTextEdit ) -> File {
280
286
<|>self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit))
281
287
}
282
288
" ,
0 commit comments