aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/parsing
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/parsing')
-rw-r--r--crates/ra_syntax/src/parsing/reparsing.rs20
1 files changed, 9 insertions, 11 deletions
diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs
index eeca94020..b4ad9e019 100644
--- a/crates/ra_syntax/src/parsing/reparsing.rs
+++ b/crates/ra_syntax/src/parsing/reparsing.rs
@@ -41,7 +41,7 @@ fn reparse_token<'node>(
41 root: &'node SyntaxNode, 41 root: &'node SyntaxNode,
42 edit: &AtomTextEdit, 42 edit: &AtomTextEdit,
43) -> Option<(GreenNode, TextRange)> { 43) -> Option<(GreenNode, TextRange)> {
44 let token = algo::find_covering_element(root, edit.delete).as_token()?; 44 let token = algo::find_covering_element(root, edit.delete).as_token()?.clone();
45 match token.kind() { 45 match token.kind() {
46 WHITESPACE | COMMENT | IDENT | STRING | RAW_STRING => { 46 WHITESPACE | COMMENT | IDENT | STRING | RAW_STRING => {
47 if token.kind() == WHITESPACE || token.kind() == COMMENT { 47 if token.kind() == WHITESPACE || token.kind() == COMMENT {
@@ -51,7 +51,7 @@ fn reparse_token<'node>(
51 } 51 }
52 } 52 }
53 53
54 let text = get_text_after_edit(token.into(), &edit); 54 let text = get_text_after_edit(token.clone().into(), &edit);
55 let lex_tokens = tokenize(&text); 55 let lex_tokens = tokenize(&text);
56 let lex_token = match lex_tokens[..] { 56 let lex_token = match lex_tokens[..] {
57 [lex_token] if lex_token.kind == token.kind() => lex_token, 57 [lex_token] if lex_token.kind == token.kind() => lex_token,
@@ -81,7 +81,7 @@ fn reparse_block<'node>(
81 edit: &AtomTextEdit, 81 edit: &AtomTextEdit,
82) -> Option<(GreenNode, Vec<SyntaxError>, TextRange)> { 82) -> Option<(GreenNode, Vec<SyntaxError>, TextRange)> {
83 let (node, reparser) = find_reparsable_node(root, edit.delete)?; 83 let (node, reparser) = find_reparsable_node(root, edit.delete)?;
84 let text = get_text_after_edit(node.into(), &edit); 84 let text = get_text_after_edit(node.clone().into(), &edit);
85 let tokens = tokenize(&text); 85 let tokens = tokenize(&text);
86 if !is_balanced(&tokens) { 86 if !is_balanced(&tokens) {
87 return None; 87 return None;
@@ -109,7 +109,7 @@ fn is_contextual_kw(text: &str) -> bool {
109 } 109 }
110} 110}
111 111
112fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(&SyntaxNode, Reparser)> { 112fn find_reparsable_node(node: &SyntaxNode, range: TextRange) -> Option<(SyntaxNode, Reparser)> {
113 let node = algo::find_covering_element(node, range); 113 let node = algo::find_covering_element(node, range);
114 let mut ancestors = match node { 114 let mut ancestors = match node {
115 SyntaxElement::Token(it) => it.parent().ancestors(), 115 SyntaxElement::Token(it) => it.parent().ancestors(),
@@ -167,8 +167,6 @@ fn merge_errors(
167 167
168#[cfg(test)] 168#[cfg(test)]
169mod tests { 169mod tests {
170 use std::sync::Arc;
171
172 use test_utils::{assert_eq_text, extract_range}; 170 use test_utils::{assert_eq_text, extract_range};
173 171
174 use super::*; 172 use super::*;
@@ -180,18 +178,18 @@ mod tests {
180 let after = edit.apply(before.clone()); 178 let after = edit.apply(before.clone());
181 179
182 let fully_reparsed = SourceFile::parse(&after); 180 let fully_reparsed = SourceFile::parse(&after);
183 let incrementally_reparsed = { 181 let incrementally_reparsed: Parse<SourceFile> = {
184 let f = SourceFile::parse(&before); 182 let f = SourceFile::parse(&before);
185 let edit = AtomTextEdit { delete: range, insert: replace_with.to_string() }; 183 let edit = AtomTextEdit { delete: range, insert: replace_with.to_string() };
186 let (green, new_errors, range) = 184 let (green, new_errors, range) =
187 incremental_reparse(f.tree.syntax(), &edit, f.errors.to_vec()).unwrap(); 185 incremental_reparse(f.tree().syntax(), &edit, f.errors.to_vec()).unwrap();
188 assert_eq!(range.len(), reparsed_len.into(), "reparsed fragment has wrong length"); 186 assert_eq!(range.len(), reparsed_len.into(), "reparsed fragment has wrong length");
189 Parse { tree: SourceFile::new(green), errors: Arc::new(new_errors) } 187 Parse::new(green, new_errors)
190 }; 188 };
191 189
192 assert_eq_text!( 190 assert_eq_text!(
193 &fully_reparsed.tree.syntax().debug_dump(), 191 &fully_reparsed.tree().syntax().debug_dump(),
194 &incrementally_reparsed.tree.syntax().debug_dump(), 192 &incrementally_reparsed.tree().syntax().debug_dump(),
195 ); 193 );
196 } 194 }
197 195