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.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs
index b4ad9e019..2f388bdfe 100644
--- a/crates/ra_syntax/src/parsing/reparsing.rs
+++ b/crates/ra_syntax/src/parsing/reparsing.rs
@@ -46,7 +46,8 @@ fn reparse_token<'node>(
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 {
48 // removing a new line may extends previous token 48 // removing a new line may extends previous token
49 if token.text().to_string()[edit.delete - token.range().start()].contains('\n') { 49 if token.text().to_string()[edit.delete - token.text_range().start()].contains('\n')
50 {
50 return None; 51 return None;
51 } 52 }
52 } 53 }
@@ -62,7 +63,7 @@ fn reparse_token<'node>(
62 return None; 63 return None;
63 } 64 }
64 65
65 if let Some(next_char) = root.text().char_at(token.range().end()) { 66 if let Some(next_char) = root.text().char_at(token.text_range().end()) {
66 let tokens_with_next_char = tokenize(&format!("{}{}", text, next_char)); 67 let tokens_with_next_char = tokenize(&format!("{}{}", text, next_char));
67 if tokens_with_next_char.len() == 1 { 68 if tokens_with_next_char.len() == 1 {
68 return None; 69 return None;
@@ -70,7 +71,7 @@ fn reparse_token<'node>(
70 } 71 }
71 72
72 let new_token = GreenToken::new(rowan::SyntaxKind(token.kind().into()), text.into()); 73 let new_token = GreenToken::new(rowan::SyntaxKind(token.kind().into()), text.into());
73 Some((token.replace_with(new_token), token.range())) 74 Some((token.replace_with(new_token), token.text_range()))
74 } 75 }
75 _ => None, 76 _ => None,
76 } 77 }
@@ -90,11 +91,12 @@ fn reparse_block<'node>(
90 let mut tree_sink = TextTreeSink::new(&text, &tokens); 91 let mut tree_sink = TextTreeSink::new(&text, &tokens);
91 reparser.parse(&mut token_source, &mut tree_sink); 92 reparser.parse(&mut token_source, &mut tree_sink);
92 let (green, new_errors) = tree_sink.finish(); 93 let (green, new_errors) = tree_sink.finish();
93 Some((node.replace_with(green), new_errors, node.range())) 94 Some((node.replace_with(green), new_errors, node.text_range()))
94} 95}
95 96
96fn get_text_after_edit(element: SyntaxElement, edit: &AtomTextEdit) -> String { 97fn get_text_after_edit(element: SyntaxElement, edit: &AtomTextEdit) -> String {
97 let edit = AtomTextEdit::replace(edit.delete - element.range().start(), edit.insert.clone()); 98 let edit =
99 AtomTextEdit::replace(edit.delete - element.text_range().start(), edit.insert.clone());
98 let text = match element { 100 let text = match element {
99 SyntaxElement::Token(token) => token.text().to_string(), 101 SyntaxElement::Token(token) => token.text().to_string(),
100 SyntaxElement::Node(node) => node.text().to_string(), 102 SyntaxElement::Node(node) => node.text().to_string(),
@@ -188,8 +190,8 @@ mod tests {
188 }; 190 };
189 191
190 assert_eq_text!( 192 assert_eq_text!(
191 &fully_reparsed.tree().syntax().debug_dump(), 193 &format!("{:#?}", fully_reparsed.tree().syntax()),
192 &incrementally_reparsed.tree().syntax().debug_dump(), 194 &format!("{:#?}", incrementally_reparsed.tree().syntax()),
193 ); 195 );
194 } 196 }
195 197