aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_editor/src
diff options
context:
space:
mode:
authorBernardo <[email protected]>2018-12-11 18:07:17 +0000
committerBernardo <[email protected]>2018-12-11 18:07:17 +0000
commit0527e3b283af0153cf13fa64fe73862a5b7655c8 (patch)
tree07c4eacaad717ea802ab26972f45223281f2c9c1 /crates/ra_editor/src
parent7344d28768c43d8955bf23c183d606be08f27c64 (diff)
rename Edit to TextEdit and AtomEdit to AtomTextEdit
Diffstat (limited to 'crates/ra_editor/src')
-rw-r--r--crates/ra_editor/src/code_actions.rs12
-rw-r--r--crates/ra_editor/src/lib.rs2
-rw-r--r--crates/ra_editor/src/typing.rs23
3 files changed, 21 insertions, 16 deletions
diff --git a/crates/ra_editor/src/code_actions.rs b/crates/ra_editor/src/code_actions.rs
index 6979251d1..688a89c3d 100644
--- a/crates/ra_editor/src/code_actions.rs
+++ b/crates/ra_editor/src/code_actions.rs
@@ -8,11 +8,11 @@ use ra_syntax::{
8 SyntaxNodeRef, TextRange, TextUnit, 8 SyntaxNodeRef, TextRange, TextUnit,
9}; 9};
10 10
11use crate::{find_node_at_offset, Edit, EditBuilder}; 11use crate::{find_node_at_offset, TextEdit, TextEditBuilder};
12 12
13#[derive(Debug)] 13#[derive(Debug)]
14pub struct LocalEdit { 14pub struct LocalEdit {
15 pub edit: Edit, 15 pub edit: TextEdit,
16 pub cursor_position: Option<TextUnit>, 16 pub cursor_position: Option<TextUnit>,
17} 17}
18 18
@@ -26,7 +26,7 @@ pub fn flip_comma<'a>(
26 let prev = non_trivia_sibling(comma, Direction::Prev)?; 26 let prev = non_trivia_sibling(comma, Direction::Prev)?;
27 let next = non_trivia_sibling(comma, Direction::Next)?; 27 let next = non_trivia_sibling(comma, Direction::Next)?;
28 Some(move || { 28 Some(move || {
29 let mut edit = EditBuilder::new(); 29 let mut edit = TextEditBuilder::new();
30 edit.replace(prev.range(), next.text().to_string()); 30 edit.replace(prev.range(), next.text().to_string());
31 edit.replace(next.range(), prev.text().to_string()); 31 edit.replace(next.range(), prev.text().to_string());
32 LocalEdit { 32 LocalEdit {
@@ -49,7 +49,7 @@ pub fn add_derive<'a>(
49 .filter(|(name, _arg)| name == "derive") 49 .filter(|(name, _arg)| name == "derive")
50 .map(|(_name, arg)| arg) 50 .map(|(_name, arg)| arg)
51 .next(); 51 .next();
52 let mut edit = EditBuilder::new(); 52 let mut edit = TextEditBuilder::new();
53 let offset = match derive_attr { 53 let offset = match derive_attr {
54 None => { 54 None => {
55 edit.insert(node_start, "#[derive()]\n".to_string()); 55 edit.insert(node_start, "#[derive()]\n".to_string());
@@ -82,7 +82,7 @@ pub fn add_impl<'a>(
82 82
83 Some(move || { 83 Some(move || {
84 let type_params = nominal.type_param_list(); 84 let type_params = nominal.type_param_list();
85 let mut edit = EditBuilder::new(); 85 let mut edit = TextEditBuilder::new();
86 let start_offset = nominal.syntax().range().end(); 86 let start_offset = nominal.syntax().range().end();
87 let mut buf = String::new(); 87 let mut buf = String::new();
88 buf.push_str("\n\nimpl"); 88 buf.push_str("\n\nimpl");
@@ -129,7 +129,7 @@ pub fn introduce_variable<'a>(
129 } 129 }
130 return Some(move || { 130 return Some(move || {
131 let mut buf = String::new(); 131 let mut buf = String::new();
132 let mut edit = EditBuilder::new(); 132 let mut edit = TextEditBuilder::new();
133 133
134 buf.push_str("let var_name = "); 134 buf.push_str("let var_name = ");
135 expr.syntax().text().push_to(&mut buf); 135 expr.syntax().text().push_to(&mut buf);
diff --git a/crates/ra_editor/src/lib.rs b/crates/ra_editor/src/lib.rs
index ddc44c778..36cabed25 100644
--- a/crates/ra_editor/src/lib.rs
+++ b/crates/ra_editor/src/lib.rs
@@ -15,7 +15,7 @@ pub use self::{
15 symbols::{file_structure, file_symbols, FileSymbol, StructureNode}, 15 symbols::{file_structure, file_symbols, FileSymbol, StructureNode},
16 typing::{join_lines, on_enter, on_eq_typed}, 16 typing::{join_lines, on_enter, on_eq_typed},
17}; 17};
18use ra_text_edit::{Edit, EditBuilder}; 18use ra_text_edit::{TextEdit, TextEditBuilder};
19use ra_syntax::{ 19use ra_syntax::{
20 algo::find_leaf_at_offset, 20 algo::find_leaf_at_offset,
21 ast::{self, AstNode, NameOwner}, 21 ast::{self, AstNode, NameOwner},
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",