From d903f37e732b1a46bc637e4c9ce39db8bdc6b880 Mon Sep 17 00:00:00 2001 From: light-ly Date: Sat, 26 Oct 2024 18:50:42 +0800 Subject: [PATCH] fix crash by rope bytes --- src/sources.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sources.rs b/src/sources.rs index 400a211..afc3e61 100644 --- a/src/sources.rs +++ b/src/sources.rs @@ -768,7 +768,8 @@ impl LSPSupport for Rope { } fn byte_to_pos(&self, byte_idx: usize) -> Position { // info!("byte_idx: {byte_idx}"); - return self.char_to_pos(self.byte_to_char(min(byte_idx, self.len_bytes() - 1))); + let self_len = if self.len_bytes() != 0 { self.len_bytes() - 1 } else { 0 }; + return self.char_to_pos(self.byte_to_char(min(byte_idx, self_len))); } fn char_to_pos(&self, char_idx: usize) -> Position { let line = self.char_to_line(char_idx);