diff options
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_syntax/src/reparsing.rs | 13 | ||||
-rw-r--r-- | crates/ra_syntax/src/text_utils.rs | 8 |
3 files changed, 6 insertions, 19 deletions
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index a75e641ea..1dbfca91b 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -31,7 +31,6 @@ mod parser_impl; | |||
31 | mod reparsing; | 31 | mod reparsing; |
32 | mod string_lexing; | 32 | mod string_lexing; |
33 | mod syntax_kinds; | 33 | mod syntax_kinds; |
34 | pub mod text_utils; | ||
35 | /// Utilities for simple uses of the parser. | 34 | /// Utilities for simple uses of the parser. |
36 | pub mod utils; | 35 | pub mod utils; |
37 | mod validation; | 36 | mod validation; |
@@ -75,8 +74,7 @@ impl SourceFile { | |||
75 | .map(|(green_node, errors)| SourceFile::new(green_node, errors)) | 74 | .map(|(green_node, errors)| SourceFile::new(green_node, errors)) |
76 | } | 75 | } |
77 | fn full_reparse(&self, edit: &AtomTextEdit) -> TreePtr<SourceFile> { | 76 | fn full_reparse(&self, edit: &AtomTextEdit) -> TreePtr<SourceFile> { |
78 | let text = | 77 | let text = edit.apply(self.syntax().text().to_string()); |
79 | text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert); | ||
80 | SourceFile::parse(&text) | 78 | SourceFile::parse(&text) |
81 | } | 79 | } |
82 | pub fn errors(&self) -> Vec<SyntaxError> { | 80 | pub fn errors(&self) -> Vec<SyntaxError> { |
diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/reparsing.rs index d5d72e1f8..2f1de6b02 100644 --- a/crates/ra_syntax/src/reparsing.rs +++ b/crates/ra_syntax/src/reparsing.rs | |||
@@ -3,7 +3,6 @@ use crate::grammar; | |||
3 | use crate::lexer::{tokenize, Token}; | 3 | use crate::lexer::{tokenize, Token}; |
4 | use crate::parser_api::Parser; | 4 | use crate::parser_api::Parser; |
5 | use crate::parser_impl; | 5 | use crate::parser_impl; |
6 | use crate::text_utils::replace_range; | ||
7 | use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNode}; | 6 | use crate::yellow::{self, GreenNode, SyntaxError, SyntaxNode}; |
8 | use crate::{SyntaxKind::*, TextRange, TextUnit}; | 7 | use crate::{SyntaxKind::*, TextRange, TextUnit}; |
9 | use ra_text_edit::AtomTextEdit; | 8 | use ra_text_edit::AtomTextEdit; |
@@ -62,11 +61,8 @@ fn reparse_block<'node>( | |||
62 | } | 61 | } |
63 | 62 | ||
64 | fn get_text_after_edit(node: &SyntaxNode, edit: &AtomTextEdit) -> String { | 63 | fn get_text_after_edit(node: &SyntaxNode, edit: &AtomTextEdit) -> String { |
65 | replace_range( | 64 | let edit = AtomTextEdit::replace(edit.delete - node.range().start(), edit.insert.clone()); |
66 | node.text().to_string(), | 65 | edit.apply(node.text().to_string()) |
67 | edit.delete - node.range().start(), | ||
68 | &edit.insert, | ||
69 | ) | ||
70 | } | 66 | } |
71 | 67 | ||
72 | fn is_contextual_kw(text: &str) -> bool { | 68 | fn is_contextual_kw(text: &str) -> bool { |
@@ -156,7 +152,7 @@ fn merge_errors( | |||
156 | mod tests { | 152 | mod tests { |
157 | use test_utils::{extract_range, assert_eq_text}; | 153 | use test_utils::{extract_range, assert_eq_text}; |
158 | 154 | ||
159 | use crate::{SourceFile, AstNode, text_utils::replace_range, utils::dump_tree}; | 155 | use crate::{SourceFile, AstNode, utils::dump_tree}; |
160 | use super::*; | 156 | use super::*; |
161 | 157 | ||
162 | fn do_check<F>(before: &str, replace_with: &str, reparser: F) | 158 | fn do_check<F>(before: &str, replace_with: &str, reparser: F) |
@@ -167,7 +163,8 @@ mod tests { | |||
167 | ) -> Option<(&'a SyntaxNode, GreenNode, Vec<SyntaxError>)>, | 163 | ) -> Option<(&'a SyntaxNode, GreenNode, Vec<SyntaxError>)>, |
168 | { | 164 | { |
169 | let (range, before) = extract_range(before); | 165 | let (range, before) = extract_range(before); |
170 | let after = replace_range(before.clone(), range, replace_with); | 166 | let edit = AtomTextEdit::replace(range, replace_with.to_owned()); |
167 | let after = edit.apply(before.clone()); | ||
171 | 168 | ||
172 | let fully_reparsed = SourceFile::parse(&after); | 169 | let fully_reparsed = SourceFile::parse(&after); |
173 | let incrementally_reparsed = { | 170 | let incrementally_reparsed = { |
diff --git a/crates/ra_syntax/src/text_utils.rs b/crates/ra_syntax/src/text_utils.rs deleted file mode 100644 index 7aaf4c223..000000000 --- a/crates/ra_syntax/src/text_utils.rs +++ /dev/null | |||
@@ -1,8 +0,0 @@ | |||
1 | use crate::TextRange; | ||
2 | |||
3 | pub fn replace_range(mut text: String, range: TextRange, replace_with: &str) -> String { | ||
4 | let start = u32::from(range.start()) as usize; | ||
5 | let end = u32::from(range.end()) as usize; | ||
6 | text.replace_range(start..end, replace_with); | ||
7 | text | ||
8 | } | ||