aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorpcpthm <[email protected]>2019-03-21 18:27:00 +0000
committerpcpthm <[email protected]>2019-03-21 23:09:11 +0000
commit9623e77d9f24b6ff8e718f7321a92081997ea1e9 (patch)
tree225485a32178a2ac9e23e624f1e14ef093f4eec5 /crates/ra_syntax
parentc622000413351915d08e270e8962f5fbaedf0437 (diff)
Fix reparsing bug when lex result is different
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/parsing/reparsing.rs11
-rw-r--r--crates/ra_syntax/tests/data/reparse/fuzz-failures/0001.rs4
-rw-r--r--crates/ra_syntax/tests/data/reparse/fuzz-failures/0002.rs4
3 files changed, 17 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/parsing/reparsing.rs b/crates/ra_syntax/src/parsing/reparsing.rs
index b44cca49d..3b5471bf8 100644
--- a/crates/ra_syntax/src/parsing/reparsing.rs
+++ b/crates/ra_syntax/src/parsing/reparsing.rs
@@ -33,10 +33,10 @@ pub(crate) fn incremental_reparse(
33} 33}
34 34
35fn reparse_leaf<'node>( 35fn reparse_leaf<'node>(
36 node: &'node SyntaxNode, 36 root: &'node SyntaxNode,
37 edit: &AtomTextEdit, 37 edit: &AtomTextEdit,
38) -> Option<(&'node SyntaxNode, GreenNode, Vec<SyntaxError>)> { 38) -> Option<(&'node SyntaxNode, GreenNode, Vec<SyntaxError>)> {
39 let node = algo::find_covering_node(node, edit.delete); 39 let node = algo::find_covering_node(root, edit.delete);
40 match node.kind() { 40 match node.kind() {
41 WHITESPACE | COMMENT | IDENT | STRING | RAW_STRING => { 41 WHITESPACE | COMMENT | IDENT | STRING | RAW_STRING => {
42 let text = get_text_after_edit(node, &edit); 42 let text = get_text_after_edit(node, &edit);
@@ -50,6 +50,13 @@ fn reparse_leaf<'node>(
50 return None; 50 return None;
51 } 51 }
52 52
53 if let Some(next_char) = root.text().char_at(node.range().end()) {
54 let tokens_with_next_char = tokenize(&format!("{}{}", text, next_char));
55 if tokens_with_next_char.len() == 1 {
56 return None;
57 }
58 }
59
53 let green = GreenNode::new_leaf(node.kind(), text.into()); 60 let green = GreenNode::new_leaf(node.kind(), text.into());
54 let new_errors = vec![]; 61 let new_errors = vec![];
55 Some((node, green, new_errors)) 62 Some((node, green, new_errors))
diff --git a/crates/ra_syntax/tests/data/reparse/fuzz-failures/0001.rs b/crates/ra_syntax/tests/data/reparse/fuzz-failures/0001.rs
new file mode 100644
index 000000000..d2d42c6f9
--- /dev/null
+++ b/crates/ra_syntax/tests/data/reparse/fuzz-failures/0001.rs
@@ -0,0 +1,4 @@
10
21
3
4bb" \ No newline at end of file
diff --git a/crates/ra_syntax/tests/data/reparse/fuzz-failures/0002.rs b/crates/ra_syntax/tests/data/reparse/fuzz-failures/0002.rs
new file mode 100644
index 000000000..3fbee1548
--- /dev/null
+++ b/crates/ra_syntax/tests/data/reparse/fuzz-failures/0002.rs
@@ -0,0 +1,4 @@
11
21
3
4""! \ No newline at end of file