From a80c07bdffc8aa9e1645339c004c12c94e60e402 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Aug 2018 15:12:17 +0300 Subject: Avoid massacaring errors --- crates/libsyntax2/src/lib.rs | 10 +++++----- crates/libsyntax2/tests/test/main.rs | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'crates/libsyntax2') diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs index d43d26c4c..9ba9970c9 100644 --- a/crates/libsyntax2/src/lib.rs +++ b/crates/libsyntax2/src/lib.rs @@ -93,7 +93,7 @@ impl File { &text, &tokens, reparser, ); let green_root = node.replace_with(green); - let errors = merge_errors(self.errors(), new_errors, edit, node.range().start()); + let errors = merge_errors(self.errors(), new_errors, node, edit); Some(File::new(green_root, errors)) } fn full_reparse(&self, edit: &AtomEdit) -> File { @@ -210,14 +210,14 @@ fn is_balanced(tokens: &[Token]) -> bool { fn merge_errors( old_errors: Vec, new_errors: Vec, + old_node: SyntaxNodeRef, edit: &AtomEdit, - node_offset: TextUnit, ) -> Vec { let mut res = Vec::new(); for e in old_errors { - if e.offset < edit.delete.start() { + if e.offset < old_node.range().start() { res.push(e) - } else if e.offset > edit.delete.end() { + } else if e.offset > old_node.range().end() { res.push(SyntaxError { msg: e.msg, offset: e.offset + TextUnit::of_str(&edit.insert) - edit.delete.len(), @@ -227,7 +227,7 @@ fn merge_errors( for e in new_errors { res.push(SyntaxError { msg: e.msg, - offset: e.offset + node_offset, + offset: e.offset + old_node.range().start(), }) } res diff --git a/crates/libsyntax2/tests/test/main.rs b/crates/libsyntax2/tests/test/main.rs index e7ae4d601..596f32216 100644 --- a/crates/libsyntax2/tests/test/main.rs +++ b/crates/libsyntax2/tests/test/main.rs @@ -59,6 +59,13 @@ struct Foo { f: foo<|><|> } ", ",\n g: (),"); + do_check(r" +fn foo { + let; + 1 + 1; + <|>92<|>; +} +", "62"); } -- cgit v1.2.3