mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Avoid massacaring errors
This commit is contained in:
parent
c3e5987c43
commit
a80c07bdff
2 changed files with 12 additions and 5 deletions
|
@ -93,7 +93,7 @@ impl File {
|
||||||
&text, &tokens, reparser,
|
&text, &tokens, reparser,
|
||||||
);
|
);
|
||||||
let green_root = node.replace_with(green);
|
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))
|
Some(File::new(green_root, errors))
|
||||||
}
|
}
|
||||||
fn full_reparse(&self, edit: &AtomEdit) -> File {
|
fn full_reparse(&self, edit: &AtomEdit) -> File {
|
||||||
|
@ -210,14 +210,14 @@ fn is_balanced(tokens: &[Token]) -> bool {
|
||||||
fn merge_errors(
|
fn merge_errors(
|
||||||
old_errors: Vec<SyntaxError>,
|
old_errors: Vec<SyntaxError>,
|
||||||
new_errors: Vec<SyntaxError>,
|
new_errors: Vec<SyntaxError>,
|
||||||
|
old_node: SyntaxNodeRef,
|
||||||
edit: &AtomEdit,
|
edit: &AtomEdit,
|
||||||
node_offset: TextUnit,
|
|
||||||
) -> Vec<SyntaxError> {
|
) -> Vec<SyntaxError> {
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
for e in old_errors {
|
for e in old_errors {
|
||||||
if e.offset < edit.delete.start() {
|
if e.offset < old_node.range().start() {
|
||||||
res.push(e)
|
res.push(e)
|
||||||
} else if e.offset > edit.delete.end() {
|
} else if e.offset > old_node.range().end() {
|
||||||
res.push(SyntaxError {
|
res.push(SyntaxError {
|
||||||
msg: e.msg,
|
msg: e.msg,
|
||||||
offset: e.offset + TextUnit::of_str(&edit.insert) - edit.delete.len(),
|
offset: e.offset + TextUnit::of_str(&edit.insert) - edit.delete.len(),
|
||||||
|
@ -227,7 +227,7 @@ fn merge_errors(
|
||||||
for e in new_errors {
|
for e in new_errors {
|
||||||
res.push(SyntaxError {
|
res.push(SyntaxError {
|
||||||
msg: e.msg,
|
msg: e.msg,
|
||||||
offset: e.offset + node_offset,
|
offset: e.offset + old_node.range().start(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
|
|
|
@ -59,6 +59,13 @@ struct Foo {
|
||||||
f: foo<|><|>
|
f: foo<|><|>
|
||||||
}
|
}
|
||||||
", ",\n g: (),");
|
", ",\n g: (),");
|
||||||
|
do_check(r"
|
||||||
|
fn foo {
|
||||||
|
let;
|
||||||
|
1 + 1;
|
||||||
|
<|>92<|>;
|
||||||
|
}
|
||||||
|
", "62");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue