Fixes crash on empty rust file. (#592)

Fixes #591

Co-authored-by: Cor Peters <luctius@gmail.com>
This commit is contained in:
Cor Peters 2021-08-16 12:18:23 +02:00 committed by GitHub
parent 78923496a6
commit ac3c1719c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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