Don't panic on empty file/buffer (#108)

pull/124/head
notoria 3 years ago committed by GitHub
parent c17dcb8633
commit 2bb71a829e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -25,6 +25,10 @@ pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
} }
let start_byte = node.start_byte(); let start_byte = node.start_byte();
let len = doc.len_bytes();
if start_byte >= len {
return None;
}
let end_byte = node.end_byte() - 1; // it's end exclusive let end_byte = node.end_byte() - 1; // it's end exclusive
let start_char = doc.byte_to_char(start_byte); let start_char = doc.byte_to_char(start_byte);
let end_char = doc.byte_to_char(end_byte); let end_char = doc.byte_to_char(end_byte);

Loading…
Cancel
Save