From 9623e77d9f24b6ff8e718f7321a92081997ea1e9 Mon Sep 17 00:00:00 2001 From: pcpthm Date: Fri, 22 Mar 2019 03:27:00 +0900 Subject: Fix reparsing bug when lex result is different --- crates/ra_syntax/src/parsing/reparsing.rs | 11 +++++++++-- crates/ra_syntax/tests/data/reparse/fuzz-failures/0001.rs | 4 ++++ crates/ra_syntax/tests/data/reparse/fuzz-failures/0002.rs | 4 ++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 crates/ra_syntax/tests/data/reparse/fuzz-failures/0001.rs create mode 100644 crates/ra_syntax/tests/data/reparse/fuzz-failures/0002.rs (limited to 'crates') 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( } fn reparse_leaf<'node>( - node: &'node SyntaxNode, + root: &'node SyntaxNode, edit: &AtomTextEdit, ) -> Option<(&'node SyntaxNode, GreenNode, Vec)> { - let node = algo::find_covering_node(node, edit.delete); + let node = algo::find_covering_node(root, edit.delete); match node.kind() { WHITESPACE | COMMENT | IDENT | STRING | RAW_STRING => { let text = get_text_after_edit(node, &edit); @@ -50,6 +50,13 @@ fn reparse_leaf<'node>( return None; } + if let Some(next_char) = root.text().char_at(node.range().end()) { + let tokens_with_next_char = tokenize(&format!("{}{}", text, next_char)); + if tokens_with_next_char.len() == 1 { + return None; + } + } + let green = GreenNode::new_leaf(node.kind(), text.into()); let new_errors = vec![]; 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 @@ +0 +1 + +bb" \ 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 @@ +1 +1 + +""! \ No newline at end of file -- cgit v1.2.3