From 1073dd632932d0c9131f6413a5ced69ee7096e60 Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Mon, 3 Apr 2023 03:58:50 +0200 Subject: robustly handle invalid LSP ranges (#6512) --- helix-term/src/ui/completion.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'helix-term') diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index e0b1419c..bc216509 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -141,16 +141,12 @@ impl Completion { } }; - let start_offset = - match util::lsp_pos_to_pos(doc.text(), edit.range.start, offset_encoding) { - Some(start) => start as i128 - primary_cursor as i128, - None => return Transaction::new(doc.text()), - }; - let end_offset = - match util::lsp_pos_to_pos(doc.text(), edit.range.end, offset_encoding) { - Some(end) => end as i128 - primary_cursor as i128, - None => return Transaction::new(doc.text()), - }; + let Some(range) = util::lsp_range_to_range(doc.text(), edit.range, offset_encoding) else{ + return Transaction::new(doc.text()); + }; + + let start_offset = range.anchor as i128 - primary_cursor as i128; + let end_offset = range.head as i128 - primary_cursor as i128; (Some((start_offset, end_offset)), edit.new_text) } else { -- cgit v1.2.3-70-g09d2