aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor/src/typing.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_editor/src/typing.rs')
-rw-r--r--crates/ra_editor/src/typing.rs23
1 files changed, 14 insertions, 9 deletions
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs
index cf9af001b..46a6e2d62 100644
--- a/crates/ra_editor/src/typing.rs
+++ b/crates/ra_editor/src/typing.rs
@@ -10,7 +10,7 @@ use ra_syntax::{
10}; 10};
11use ra_text_edit::text_utils::contains_offset_nonstrict; 11use ra_text_edit::text_utils::contains_offset_nonstrict;
12 12
13use crate::{find_node_at_offset, EditBuilder, LocalEdit}; 13use crate::{find_node_at_offset, TextEditBuilder, LocalEdit};
14 14
15pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit { 15pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit {
16 let range = if range.is_empty() { 16 let range = if range.is_empty() {
@@ -19,7 +19,7 @@ pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit {
19 let pos = match text.find('\n') { 19 let pos = match text.find('\n') {
20 None => { 20 None => {
21 return LocalEdit { 21 return LocalEdit {
22 edit: EditBuilder::new().finish(), 22 edit: TextEditBuilder::new().finish(),
23 cursor_position: None, 23 cursor_position: None,
24 }; 24 };
25 } 25 }
@@ -31,7 +31,7 @@ pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit {
31 }; 31 };
32 32
33 let node = find_covering_node(file.syntax(), range); 33 let node = find_covering_node(file.syntax(), range);
34 let mut edit = EditBuilder::new(); 34 let mut edit = TextEditBuilder::new();
35 for node in node.descendants() { 35 for node in node.descendants() {
36 let text = match node.leaf_text() { 36 let text = match node.leaf_text() {
37 Some(text) => text, 37 Some(text) => text,
@@ -73,7 +73,7 @@ pub fn on_enter(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> {
73 let indent = node_indent(file, comment.syntax())?; 73 let indent = node_indent(file, comment.syntax())?;
74 let inserted = format!("\n{}{} ", indent, prefix); 74 let inserted = format!("\n{}{} ", indent, prefix);
75 let cursor_position = offset + TextUnit::of_str(&inserted); 75 let cursor_position = offset + TextUnit::of_str(&inserted);
76 let mut edit = EditBuilder::new(); 76 let mut edit = TextEditBuilder::new();
77 edit.insert(offset, inserted); 77 edit.insert(offset, inserted);
78 Some(LocalEdit { 78 Some(LocalEdit {
79 edit: edit.finish(), 79 edit: edit.finish(),
@@ -123,7 +123,7 @@ pub fn on_eq_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit>
123 return None; 123 return None;
124 } 124 }
125 let offset = let_stmt.syntax().range().end(); 125 let offset = let_stmt.syntax().range().end();
126 let mut edit = EditBuilder::new(); 126 let mut edit = TextEditBuilder::new();
127 edit.insert(offset, ";".to_string()); 127 edit.insert(offset, ";".to_string());
128 Some(LocalEdit { 128 Some(LocalEdit {
129 edit: edit.finish(), 129 edit: edit.finish(),
@@ -131,7 +131,12 @@ pub fn on_eq_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit>
131 }) 131 })
132} 132}
133 133
134fn remove_newline(edit: &mut EditBuilder, node: SyntaxNodeRef, node_text: &str, offset: TextUnit) { 134fn remove_newline(
135 edit: &mut TextEditBuilder,
136 node: SyntaxNodeRef,
137 node_text: &str,
138 offset: TextUnit,
139) {
135 if node.kind() != WHITESPACE || node_text.bytes().filter(|&b| b == b'\n').count() != 1 { 140 if node.kind() != WHITESPACE || node_text.bytes().filter(|&b| b == b'\n').count() != 1 {
136 // The node is either the first or the last in the file 141 // The node is either the first or the last in the file
137 let suff = &node_text[TextRange::from_to( 142 let suff = &node_text[TextRange::from_to(
@@ -192,7 +197,7 @@ fn is_trailing_comma(left: SyntaxKind, right: SyntaxKind) -> bool {
192 } 197 }
193} 198}
194 199
195fn join_single_expr_block(edit: &mut EditBuilder, node: SyntaxNodeRef) -> Option<()> { 200fn join_single_expr_block(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Option<()> {
196 let block = ast::Block::cast(node.parent()?)?; 201 let block = ast::Block::cast(node.parent()?)?;
197 let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?; 202 let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?;
198 let expr = single_expr(block)?; 203 let expr = single_expr(block)?;
@@ -270,14 +275,14 @@ fn foo() {
270 fn test_join_lines_lambda_block() { 275 fn test_join_lines_lambda_block() {
271 check_join_lines( 276 check_join_lines(
272 r" 277 r"
273pub fn reparse(&self, edit: &AtomEdit) -> File { 278pub fn reparse(&self, edit: &AtomTextEdit) -> File {
274 <|>self.incremental_reparse(edit).unwrap_or_else(|| { 279 <|>self.incremental_reparse(edit).unwrap_or_else(|| {
275 self.full_reparse(edit) 280 self.full_reparse(edit)
276 }) 281 })
277} 282}
278", 283",
279 r" 284 r"
280pub fn reparse(&self, edit: &AtomEdit) -> File { 285pub fn reparse(&self, edit: &AtomTextEdit) -> File {
281 <|>self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit)) 286 <|>self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit))
282} 287}
283", 288",