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

This commit is contained in:
notoria 2021-06-05 06:00:43 +02:00 committed by GitHub
parent c17dcb8633
commit 2bb71a829e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,6 +25,10 @@ pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
}
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 start_char = doc.byte_to_char(start_byte);
let end_char = doc.byte_to_char(end_byte);