diff options
author | Bernardo <[email protected]> | 2018-12-11 18:07:17 +0000 |
---|---|---|
committer | Bernardo <[email protected]> | 2018-12-11 18:07:17 +0000 |
commit | 0527e3b283af0153cf13fa64fe73862a5b7655c8 (patch) | |
tree | 07c4eacaad717ea802ab26972f45223281f2c9c1 | |
parent | 7344d28768c43d8955bf23c183d606be08f27c64 (diff) |
rename Edit to TextEdit and AtomEdit to AtomTextEdit
-rw-r--r-- | crates/ra_analysis/src/completion.rs | 4 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_editor/src/code_actions.rs | 12 | ||||
-rw-r--r-- | crates/ra_editor/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_editor/src/typing.rs | 23 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 22 | ||||
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_syntax/src/reparsing.rs | 16 | ||||
-rw-r--r-- | crates/ra_syntax/tests/data/parser/fuzz-failures/0000.rs | 38 | ||||
-rw-r--r-- | crates/ra_text_edit/src/lib.rs | 20 | ||||
-rw-r--r-- | crates/ra_text_edit/src/text_edit.rs (renamed from crates/ra_text_edit/src/edit.rs) | 30 |
11 files changed, 92 insertions, 87 deletions
diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs index e83330966..f480af611 100644 --- a/crates/ra_analysis/src/completion.rs +++ b/crates/ra_analysis/src/completion.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | mod reference_completion; | 1 | mod reference_completion; |
2 | 2 | ||
3 | use ra_editor::find_node_at_offset; | 3 | use ra_editor::find_node_at_offset; |
4 | use ra_text_edit::AtomEdit; | 4 | use ra_text_edit::AtomTextEdit; |
5 | use ra_syntax::{ | 5 | use ra_syntax::{ |
6 | algo::visit::{visitor_ctx, VisitorCtx}, | 6 | algo::visit::{visitor_ctx, VisitorCtx}, |
7 | ast, | 7 | ast, |
@@ -34,7 +34,7 @@ pub(crate) fn completions( | |||
34 | let original_file = db.source_file(position.file_id); | 34 | let original_file = db.source_file(position.file_id); |
35 | // Insert a fake ident to get a valid parse tree | 35 | // Insert a fake ident to get a valid parse tree |
36 | let file = { | 36 | let file = { |
37 | let edit = AtomEdit::insert(position.offset, "intellijRulezz".to_string()); | 37 | let edit = AtomTextEdit::insert(position.offset, "intellijRulezz".to_string()); |
38 | original_file.reparse(&edit) | 38 | original_file.reparse(&edit) |
39 | }; | 39 | }; |
40 | 40 | ||
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 2f8f1dab5..22fff71ab 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -19,7 +19,7 @@ pub mod mock_analysis; | |||
19 | use std::{fmt, sync::Arc}; | 19 | use std::{fmt, sync::Arc}; |
20 | 20 | ||
21 | use ra_syntax::{SourceFileNode, TextRange, TextUnit}; | 21 | use ra_syntax::{SourceFileNode, TextRange, TextUnit}; |
22 | use ra_text_edit::AtomEdit; | 22 | use ra_text_edit::AtomTextEdit; |
23 | use ra_db::FileResolverImp; | 23 | use ra_db::FileResolverImp; |
24 | use rayon::prelude::*; | 24 | use rayon::prelude::*; |
25 | use relative_path::RelativePathBuf; | 25 | use relative_path::RelativePathBuf; |
@@ -121,7 +121,7 @@ pub struct SourceChange { | |||
121 | #[derive(Debug)] | 121 | #[derive(Debug)] |
122 | pub struct SourceFileNodeEdit { | 122 | pub struct SourceFileNodeEdit { |
123 | pub file_id: FileId, | 123 | pub file_id: FileId, |
124 | pub edits: Vec<AtomEdit>, | 124 | pub edits: Vec<AtomTextEdit>, |
125 | } | 125 | } |
126 | 126 | ||
127 | #[derive(Debug)] | 127 | #[derive(Debug)] |
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 | ||
11 | use crate::{find_node_at_offset, Edit, EditBuilder}; | 11 | use crate::{find_node_at_offset, TextEdit, TextEditBuilder}; |
12 | 12 | ||
13 | #[derive(Debug)] | 13 | #[derive(Debug)] |
14 | pub struct LocalEdit { | 14 | pub 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 | }; |
18 | use ra_text_edit::{Edit, EditBuilder}; | 18 | use ra_text_edit::{TextEdit, TextEditBuilder}; |
19 | use ra_syntax::{ | 19 | use 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 | }; |
11 | use ra_text_edit::text_utils::contains_offset_nonstrict; | 11 | use ra_text_edit::text_utils::contains_offset_nonstrict; |
12 | 12 | ||
13 | use crate::{find_node_at_offset, EditBuilder, LocalEdit}; | 13 | use crate::{find_node_at_offset, TextEditBuilder, LocalEdit}; |
14 | 14 | ||
15 | pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit { | 15 | pub 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 | ||
134 | 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 | ) { | ||
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 | ||
195 | fn join_single_expr_block(edit: &mut EditBuilder, node: SyntaxNodeRef) -> Option<()> { | 200 | fn 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" |
273 | pub fn reparse(&self, edit: &AtomEdit) -> File { | 278 | pub 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" |
280 | pub fn reparse(&self, edit: &AtomEdit) -> File { | 285 | pub 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 | ", |
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 8bf8576be..7467f472c 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -1,10 +1,10 @@ | |||
1 | use languageserver_types::{ | 1 | use languageserver_types::{ |
2 | Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, | 2 | self, Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, |
3 | TextDocumentItem, TextDocumentPositionParams, TextEdit, Url, VersionedTextDocumentIdentifier, | 3 | TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, |
4 | }; | 4 | }; |
5 | use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileNodeEdit, FilePosition}; | 5 | use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileNodeEdit, FilePosition}; |
6 | use ra_editor::{LineCol, LineIndex}; | 6 | use ra_editor::{LineCol, LineIndex}; |
7 | use ra_text_edit::{AtomEdit, Edit}; | 7 | use ra_text_edit::{AtomTextEdit, TextEdit}; |
8 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; | 8 | use ra_syntax::{SyntaxKind, TextRange, TextUnit}; |
9 | 9 | ||
10 | use crate::{req, server_world::ServerWorld, Result}; | 10 | use crate::{req, server_world::ServerWorld, Result}; |
@@ -92,11 +92,11 @@ impl ConvWith for Range { | |||
92 | } | 92 | } |
93 | } | 93 | } |
94 | 94 | ||
95 | impl ConvWith for Edit { | 95 | impl ConvWith for TextEdit { |
96 | type Ctx = LineIndex; | 96 | type Ctx = LineIndex; |
97 | type Output = Vec<TextEdit>; | 97 | type Output = Vec<languageserver_types::TextEdit>; |
98 | 98 | ||
99 | fn conv_with(self, line_index: &LineIndex) -> Vec<TextEdit> { | 99 | fn conv_with(self, line_index: &LineIndex) -> Vec<languageserver_types::TextEdit> { |
100 | self.into_atoms() | 100 | self.into_atoms() |
101 | .into_iter() | 101 | .into_iter() |
102 | .map_conv_with(line_index) | 102 | .map_conv_with(line_index) |
@@ -104,12 +104,12 @@ impl ConvWith for Edit { | |||
104 | } | 104 | } |
105 | } | 105 | } |
106 | 106 | ||
107 | impl ConvWith for AtomEdit { | 107 | impl ConvWith for AtomTextEdit { |
108 | type Ctx = LineIndex; | 108 | type Ctx = LineIndex; |
109 | type Output = TextEdit; | 109 | type Output = languageserver_types::TextEdit; |
110 | 110 | ||
111 | fn conv_with(self, line_index: &LineIndex) -> TextEdit { | 111 | fn conv_with(self, line_index: &LineIndex) -> languageserver_types::TextEdit { |
112 | TextEdit { | 112 | languageserver_types::TextEdit { |
113 | range: self.delete.conv_with(line_index), | 113 | range: self.delete.conv_with(line_index), |
114 | new_text: self.insert, | 114 | new_text: self.insert, |
115 | } | 115 | } |
@@ -229,7 +229,7 @@ impl TryConvWith for SourceChange { | |||
229 | fn translate_offset_with_edit( | 229 | fn translate_offset_with_edit( |
230 | pre_edit_index: &LineIndex, | 230 | pre_edit_index: &LineIndex, |
231 | offset: TextUnit, | 231 | offset: TextUnit, |
232 | edits: &[AtomEdit], | 232 | edits: &[AtomTextEdit], |
233 | ) -> LineCol { | 233 | ) -> LineCol { |
234 | let fallback = pre_edit_index.line_col(offset); | 234 | let fallback = pre_edit_index.line_col(offset); |
235 | let edit = match edits.first() { | 235 | let edit = match edits.first() { |
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 7295fb237..34a3aabef 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -47,7 +47,7 @@ pub use crate::{ | |||
47 | }, | 47 | }, |
48 | }; | 48 | }; |
49 | 49 | ||
50 | use ra_text_edit::AtomEdit; | 50 | use ra_text_edit::AtomTextEdit; |
51 | use crate::yellow::GreenNode; | 51 | use crate::yellow::GreenNode; |
52 | 52 | ||
53 | /// `SourceFileNode` represents a parse tree for a single Rust file. | 53 | /// `SourceFileNode` represents a parse tree for a single Rust file. |
@@ -68,15 +68,15 @@ impl SourceFileNode { | |||
68 | parser_impl::parse_with(yellow::GreenBuilder::new(), text, &tokens, grammar::root); | 68 | parser_impl::parse_with(yellow::GreenBuilder::new(), text, &tokens, grammar::root); |
69 | SourceFileNode::new(green, errors) | 69 | SourceFileNode::new(green, errors) |
70 | } | 70 | } |
71 | pub fn reparse(&self, edit: &AtomEdit) -> SourceFileNode { | 71 | pub fn reparse(&self, edit: &AtomTextEdit) -> SourceFileNode { |
72 | self.incremental_reparse(edit) | 72 | self.incremental_reparse(edit) |
73 | .unwrap_or_else(|| self.full_reparse(edit)) | 73 | .unwrap_or_else(|| self.full_reparse(edit)) |
74 | } | 74 | } |
75 | pub fn incremental_reparse(&self, edit: &AtomEdit) -> Option<SourceFileNode> { | 75 | pub fn incremental_reparse(&self, edit: &AtomTextEdit) -> Option<SourceFileNode> { |
76 | reparsing::incremental_reparse(self.syntax(), edit, self.errors()) | 76 | reparsing::incremental_reparse(self.syntax(), edit, self.errors()) |
77 | .map(|(green_node, errors)| SourceFileNode::new(green_node, errors)) | 77 | .map(|(green_node, errors)| SourceFileNode::new(green_node, errors)) |
78 | } | 78 | } |
79 | fn full_reparse(&self, edit: &AtomEdit) -> SourceFileNode { | 79 | fn full_reparse(&self, edit: &AtomTextEdit) -> SourceFileNode { |
80 | let text = | 80 | let text = |
81 | text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert); | 81 | text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert); |
82 | SourceFileNode::parse(&text) | 82 | SourceFileNode::parse(&text) |
diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/reparsing.rs index 873809a5a..208cae5c8 100644 --- a/crates/ra_syntax/src/reparsing.rs +++ b/crates/ra_syntax/src/reparsing.rs | |||
@@ -6,11 +6,11 @@ use crate::parser_impl; | |||
6 | use crate::text_utils::replace_range; | 6 | use crate::text_utils::replace_range; |
7 | use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNodeRef}; | 7 | use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNodeRef}; |
8 | use crate::{SyntaxKind::*, TextRange, TextUnit}; | 8 | use crate::{SyntaxKind::*, TextRange, TextUnit}; |
9 | use ra_text_edit::AtomEdit; | 9 | use ra_text_edit::AtomTextEdit; |
10 | 10 | ||
11 | pub(crate) fn incremental_reparse( | 11 | pub(crate) fn incremental_reparse( |
12 | node: SyntaxNodeRef, | 12 | node: SyntaxNodeRef, |
13 | edit: &AtomEdit, | 13 | edit: &AtomTextEdit, |
14 | errors: Vec<SyntaxError>, | 14 | errors: Vec<SyntaxError>, |
15 | ) -> Option<(GreenNode, Vec<SyntaxError>)> { | 15 | ) -> Option<(GreenNode, Vec<SyntaxError>)> { |
16 | let (node, green, new_errors) = | 16 | let (node, green, new_errors) = |
@@ -22,7 +22,7 @@ pub(crate) fn incremental_reparse( | |||
22 | 22 | ||
23 | fn reparse_leaf<'node>( | 23 | fn reparse_leaf<'node>( |
24 | node: SyntaxNodeRef<'node>, | 24 | node: SyntaxNodeRef<'node>, |
25 | edit: &AtomEdit, | 25 | edit: &AtomTextEdit, |
26 | ) -> Option<(SyntaxNodeRef<'node>, GreenNode, Vec<SyntaxError>)> { | 26 | ) -> Option<(SyntaxNodeRef<'node>, GreenNode, Vec<SyntaxError>)> { |
27 | let node = algo::find_covering_node(node, edit.delete); | 27 | let node = algo::find_covering_node(node, edit.delete); |
28 | match node.kind() { | 28 | match node.kind() { |
@@ -48,7 +48,7 @@ fn reparse_leaf<'node>( | |||
48 | 48 | ||
49 | fn reparse_block<'node>( | 49 | fn reparse_block<'node>( |
50 | node: SyntaxNodeRef<'node>, | 50 | node: SyntaxNodeRef<'node>, |
51 | edit: &AtomEdit, | 51 | edit: &AtomTextEdit, |
52 | ) -> Option<(SyntaxNodeRef<'node>, GreenNode, Vec<SyntaxError>)> { | 52 | ) -> Option<(SyntaxNodeRef<'node>, GreenNode, Vec<SyntaxError>)> { |
53 | let (node, reparser) = find_reparsable_node(node, edit.delete)?; | 53 | let (node, reparser) = find_reparsable_node(node, edit.delete)?; |
54 | let text = get_text_after_edit(node, &edit); | 54 | let text = get_text_after_edit(node, &edit); |
@@ -61,7 +61,7 @@ fn reparse_block<'node>( | |||
61 | Some((node, green, new_errors)) | 61 | Some((node, green, new_errors)) |
62 | } | 62 | } |
63 | 63 | ||
64 | fn get_text_after_edit(node: SyntaxNodeRef, edit: &AtomEdit) -> String { | 64 | fn get_text_after_edit(node: SyntaxNodeRef, edit: &AtomTextEdit) -> String { |
65 | replace_range( | 65 | replace_range( |
66 | node.text().to_string(), | 66 | node.text().to_string(), |
67 | edit.delete - node.range().start(), | 67 | edit.delete - node.range().start(), |
@@ -139,7 +139,7 @@ fn merge_errors( | |||
139 | old_errors: Vec<SyntaxError>, | 139 | old_errors: Vec<SyntaxError>, |
140 | new_errors: Vec<SyntaxError>, | 140 | new_errors: Vec<SyntaxError>, |
141 | old_node: SyntaxNodeRef, | 141 | old_node: SyntaxNodeRef, |
142 | edit: &AtomEdit, | 142 | edit: &AtomTextEdit, |
143 | ) -> Vec<SyntaxError> { | 143 | ) -> Vec<SyntaxError> { |
144 | let mut res = Vec::new(); | 144 | let mut res = Vec::new(); |
145 | for e in old_errors { | 145 | for e in old_errors { |
@@ -166,7 +166,7 @@ mod tests { | |||
166 | where | 166 | where |
167 | for<'a> F: Fn( | 167 | for<'a> F: Fn( |
168 | SyntaxNodeRef<'a>, | 168 | SyntaxNodeRef<'a>, |
169 | &AtomEdit, | 169 | &AtomTextEdit, |
170 | ) -> Option<(SyntaxNodeRef<'a>, GreenNode, Vec<SyntaxError>)>, | 170 | ) -> Option<(SyntaxNodeRef<'a>, GreenNode, Vec<SyntaxError>)>, |
171 | { | 171 | { |
172 | let (range, before) = extract_range(before); | 172 | let (range, before) = extract_range(before); |
@@ -175,7 +175,7 @@ mod tests { | |||
175 | let fully_reparsed = SourceFileNode::parse(&after); | 175 | let fully_reparsed = SourceFileNode::parse(&after); |
176 | let incrementally_reparsed = { | 176 | let incrementally_reparsed = { |
177 | let f = SourceFileNode::parse(&before); | 177 | let f = SourceFileNode::parse(&before); |
178 | let edit = AtomEdit { | 178 | let edit = AtomTextEdit { |
179 | delete: range, | 179 | delete: range, |
180 | insert: replace_with.to_string(), | 180 | insert: replace_with.to_string(), |
181 | }; | 181 | }; |
diff --git a/crates/ra_syntax/tests/data/parser/fuzz-failures/0000.rs b/crates/ra_syntax/tests/data/parser/fuzz-failures/0000.rs index 53c93d9e9..59cd11495 100644 --- a/crates/ra_syntax/tests/data/parser/fuzz-failures/0000.rs +++ b/crates/ra_syntax/tests/data/parser/fuzz-failures/0000.rs | |||
@@ -10,10 +10,10 @@ | |||
10 | ); | 10 | ); |
11 | File::new(green, errors) | 11 | File::new(green, errors) |
12 | } | 12 | } |
13 | pub fn reparse(&self, edit: &AtomEdit) -> File { | 13 | pub fn reparse(&self, edit: &AtomTextEdit) -> File { |
14 | self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit)) | 14 | self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit)) |
15 | } | 15 | } |
16 | pub fn incremental_reparse(&self, edit: &AtomEdit) -> Option<File> { | 16 | pub fn incremental_reparse(&self, edit: &AtomTextEdit) -> Option<File> { |
17 | let (node, reparser) = find_reparsable_node(self.syntax(), edit.delete)?; | 17 | let (node, reparser) = find_reparsable_node(self.syntax(), edit.delete)?; |
18 | let text = replace_range( | 18 | let text = replace_range( |
19 | node.text().to_string(), | 19 | node.text().to_string(), |
@@ -31,7 +31,7 @@ | |||
31 | let errors = merge_errors(self.errors(), new_errors, node, edit); | 31 | let errors = merge_errors(self.errors(), new_errors, node, edit); |
32 | Some(File::new(green_root, errors)) | 32 | Some(File::new(green_root, errors)) |
33 | } | 33 | } |
34 | fn full_reparse(&self, edit: &AtomEdit) -> File { | 34 | fn full_reparse(&self, edit: &AtomTextEdit) -> File { |
35 | let text = replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert); | 35 | let text = replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert); |
36 | File::parse(&text) | 36 | File::parse(&text) |
37 | } | 37 | } |
@@ -58,22 +58,22 @@ | |||
58 | } | 58 | } |
59 | 59 | ||
60 | #[derive(Debug, Clone)] | 60 | #[derive(Debug, Clone)] |
61 | pub struct AtomEdit { | 61 | pub struct AtomTextEdit { |
62 | pub delete: TextRange, | 62 | pub delete: TextRange, |
63 | pub insert: String, | 63 | pub insert: String, |
64 | } | 64 | } |
65 | 65 | ||
66 | impl AtomEdit { | 66 | impl AtomTextEdit { |
67 | pub fn replace(range: TextRange, replace_with: String) -> AtomEdit { | 67 | pub fn replace(range: TextRange, replace_with: String) -> AtomTextEdit { |
68 | AtomEdit { delete: range, insert: replace_with } | 68 | AtomTextEdit { delete: range, insert: replace_with } |
69 | } | 69 | } |
70 | 70 | ||
71 | pub fn delete(range: TextRange) -> AtomEdit { | 71 | pub fn delete(range: TextRange) -> AtomTextEdit { |
72 | AtomEdit::replace(range, String::new()) | 72 | AtomTextEdit::replace(range, String::new()) |
73 | } | 73 | } |
74 | 74 | ||
75 | pub fn insert(offset: TextUnit, text: String) -> AtomEdit { | 75 | pub fn insert(offset: TextUnit, text: String) -> AtomTextEdit { |
76 | AtomEdit::replace(TextRange::offset_len(offset, 0.into()), text) | 76 | AtomTextEdit::replace(TextRange::offset_len(offset, 0.into()), text) |
77 | } | 77 | } |
78 | } | 78 | } |
79 | 79 | ||
@@ -114,17 +114,17 @@ fn is_balanced(tokens: &[Token]) -> bool { | |||
114 | pub insert: String, | 114 | pub insert: String, |
115 | } | 115 | } |
116 | 116 | ||
117 | impl AtomEdit { | 117 | impl AtomTextEdit { |
118 | pub fn replace(range: TextRange, replace_with: String) -> AtomEdit { | 118 | pub fn replace(range: TextRange, replace_with: String) -> AtomTextEdit { |
119 | AtomEdit { delete: range, insert: replace_with } | 119 | AtomTextEdit { delete: range, insert: replace_with } |
120 | } | 120 | } |
121 | 121 | ||
122 | pub fn delete(range: TextRange) -> AtomEdit { | 122 | pub fn delete(range: TextRange) -> AtomTextEdit { |
123 | AtomEdit::replace(range, String::new()) | 123 | AtomTextEdit::replace(range, String::new()) |
124 | } | 124 | } |
125 | 125 | ||
126 | pub fn insert(offset: TextUnit, text: String) -> AtomEdit { | 126 | pub fn insert(offset: TextUnit, text: String) -> AtomTextEdit { |
127 | AtomEdit::replace(TextRange::offset_len(offset, 0.into()), text) | 127 | AtomTextEdit::replace(TextRange::offset_len(offset, 0.into()), text) |
128 | } | 128 | } |
129 | } | 129 | } |
130 | 130 | ||
@@ -176,7 +176,7 @@ fn merge_errors( | |||
176 | old_errors: Vec<SyntaxError>, | 176 | old_errors: Vec<SyntaxError>, |
177 | new_errors: Vec<SyntaxError>, | 177 | new_errors: Vec<SyntaxError>, |
178 | old_node: SyntaxNodeRef, | 178 | old_node: SyntaxNodeRef, |
179 | edit: &AtomEdit, | 179 | edit: &AtomTextEdit, |
180 | ) -> Vec<SyntaxError> { | 180 | ) -> Vec<SyntaxError> { |
181 | let mut res = Vec::new(); | 181 | let mut res = Vec::new(); |
182 | for e in old_errors { | 182 | for e in old_errors { |
diff --git a/crates/ra_text_edit/src/lib.rs b/crates/ra_text_edit/src/lib.rs index 789471e8a..13e20f6fb 100644 --- a/crates/ra_text_edit/src/lib.rs +++ b/crates/ra_text_edit/src/lib.rs | |||
@@ -1,29 +1,29 @@ | |||
1 | mod edit; | 1 | mod text_edit; |
2 | pub mod text_utils; | 2 | pub mod text_utils; |
3 | 3 | ||
4 | pub use crate::edit::{Edit, EditBuilder}; | 4 | pub use crate::text_edit::{TextEdit, TextEditBuilder}; |
5 | 5 | ||
6 | use text_unit::{TextRange, TextUnit}; | 6 | use text_unit::{TextRange, TextUnit}; |
7 | 7 | ||
8 | #[derive(Debug, Clone)] | 8 | #[derive(Debug, Clone)] |
9 | pub struct AtomEdit { | 9 | pub struct AtomTextEdit { |
10 | pub delete: TextRange, | 10 | pub delete: TextRange, |
11 | pub insert: String, | 11 | pub insert: String, |
12 | } | 12 | } |
13 | 13 | ||
14 | impl AtomEdit { | 14 | impl AtomTextEdit { |
15 | pub fn replace(range: TextRange, replace_with: String) -> AtomEdit { | 15 | pub fn replace(range: TextRange, replace_with: String) -> AtomTextEdit { |
16 | AtomEdit { | 16 | AtomTextEdit { |
17 | delete: range, | 17 | delete: range, |
18 | insert: replace_with, | 18 | insert: replace_with, |
19 | } | 19 | } |
20 | } | 20 | } |
21 | 21 | ||
22 | pub fn delete(range: TextRange) -> AtomEdit { | 22 | pub fn delete(range: TextRange) -> AtomTextEdit { |
23 | AtomEdit::replace(range, String::new()) | 23 | AtomTextEdit::replace(range, String::new()) |
24 | } | 24 | } |
25 | 25 | ||
26 | pub fn insert(offset: TextUnit, text: String) -> AtomEdit { | 26 | pub fn insert(offset: TextUnit, text: String) -> AtomTextEdit { |
27 | AtomEdit::replace(TextRange::offset_len(offset, 0.into()), text) | 27 | AtomTextEdit::replace(TextRange::offset_len(offset, 0.into()), text) |
28 | } | 28 | } |
29 | } | 29 | } |
diff --git a/crates/ra_text_edit/src/edit.rs b/crates/ra_text_edit/src/text_edit.rs index 560cf2bbc..fb46f046d 100644 --- a/crates/ra_text_edit/src/edit.rs +++ b/crates/ra_text_edit/src/text_edit.rs | |||
@@ -1,37 +1,37 @@ | |||
1 | use crate::AtomEdit; | 1 | use crate::AtomTextEdit; |
2 | use crate::text_utils::contains_offset_nonstrict; | 2 | use crate::text_utils::contains_offset_nonstrict; |
3 | use text_unit::{TextRange, TextUnit}; | 3 | use text_unit::{TextRange, TextUnit}; |
4 | 4 | ||
5 | #[derive(Debug, Clone)] | 5 | #[derive(Debug, Clone)] |
6 | pub struct Edit { | 6 | pub struct TextEdit { |
7 | atoms: Vec<AtomEdit>, | 7 | atoms: Vec<AtomTextEdit>, |
8 | } | 8 | } |
9 | 9 | ||
10 | #[derive(Debug)] | 10 | #[derive(Debug)] |
11 | pub struct EditBuilder { | 11 | pub struct TextEditBuilder { |
12 | atoms: Vec<AtomEdit>, | 12 | atoms: Vec<AtomTextEdit>, |
13 | } | 13 | } |
14 | 14 | ||
15 | impl EditBuilder { | 15 | impl TextEditBuilder { |
16 | pub fn new() -> EditBuilder { | 16 | pub fn new() -> TextEditBuilder { |
17 | EditBuilder { atoms: Vec::new() } | 17 | TextEditBuilder { atoms: Vec::new() } |
18 | } | 18 | } |
19 | pub fn replace(&mut self, range: TextRange, replace_with: String) { | 19 | pub fn replace(&mut self, range: TextRange, replace_with: String) { |
20 | self.atoms.push(AtomEdit::replace(range, replace_with)) | 20 | self.atoms.push(AtomTextEdit::replace(range, replace_with)) |
21 | } | 21 | } |
22 | pub fn delete(&mut self, range: TextRange) { | 22 | pub fn delete(&mut self, range: TextRange) { |
23 | self.atoms.push(AtomEdit::delete(range)) | 23 | self.atoms.push(AtomTextEdit::delete(range)) |
24 | } | 24 | } |
25 | pub fn insert(&mut self, offset: TextUnit, text: String) { | 25 | pub fn insert(&mut self, offset: TextUnit, text: String) { |
26 | self.atoms.push(AtomEdit::insert(offset, text)) | 26 | self.atoms.push(AtomTextEdit::insert(offset, text)) |
27 | } | 27 | } |
28 | pub fn finish(self) -> Edit { | 28 | pub fn finish(self) -> TextEdit { |
29 | let mut atoms = self.atoms; | 29 | let mut atoms = self.atoms; |
30 | atoms.sort_by_key(|a| (a.delete.start(), a.delete.end())); | 30 | atoms.sort_by_key(|a| (a.delete.start(), a.delete.end())); |
31 | for (a1, a2) in atoms.iter().zip(atoms.iter().skip(1)) { | 31 | for (a1, a2) in atoms.iter().zip(atoms.iter().skip(1)) { |
32 | assert!(a1.delete.end() <= a2.delete.start()) | 32 | assert!(a1.delete.end() <= a2.delete.start()) |
33 | } | 33 | } |
34 | Edit { atoms } | 34 | TextEdit { atoms } |
35 | } | 35 | } |
36 | pub fn invalidates_offset(&self, offset: TextUnit) -> bool { | 36 | pub fn invalidates_offset(&self, offset: TextUnit) -> bool { |
37 | self.atoms | 37 | self.atoms |
@@ -40,8 +40,8 @@ impl EditBuilder { | |||
40 | } | 40 | } |
41 | } | 41 | } |
42 | 42 | ||
43 | impl Edit { | 43 | impl TextEdit { |
44 | pub fn into_atoms(self) -> Vec<AtomEdit> { | 44 | pub fn into_atoms(self) -> Vec<AtomTextEdit> { |
45 | self.atoms | 45 | self.atoms |
46 | } | 46 | } |
47 | 47 | ||