diff options
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/application.rs | 25 | ||||
-rw-r--r-- | helix-term/src/commands.rs | 13 |
2 files changed, 25 insertions, 13 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index bf829f2c..3d043441 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -178,7 +178,7 @@ impl Application { let diagnostics = params .diagnostics .into_iter() - .map(|diagnostic| { + .filter_map(|diagnostic| { use helix_core::{ diagnostic::{Range, Severity, Severity::*}, Diagnostic, @@ -189,18 +189,29 @@ impl Application { let language_server = doc.language_server().unwrap(); // TODO: convert inside server - let start = lsp_pos_to_pos( + let start = if let Some(start) = lsp_pos_to_pos( text, diagnostic.range.start, language_server.offset_encoding(), - ); - let end = lsp_pos_to_pos( + ) { + start + } else { + log::warn!("lsp position out of bounds - {:?}", diagnostic); + return None; + }; + + let end = if let Some(end) = lsp_pos_to_pos( text, diagnostic.range.end, language_server.offset_encoding(), - ); + ) { + end + } else { + log::warn!("lsp position out of bounds - {:?}", diagnostic); + return None; + }; - Diagnostic { + Some(Diagnostic { range: Range { start, end }, line: diagnostic.range.start.line as usize, message: diagnostic.message, @@ -214,7 +225,7 @@ impl Application { ), // code // source - } + }) }) .collect(); diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index edc3dcfd..f9db5581 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1407,7 +1407,12 @@ fn _goto( let (view, doc) = editor.current(); let definition_pos = location.range.start; // TODO: convert inside server - let new_pos = lsp_pos_to_pos(doc.text(), definition_pos, offset_encoding); + let new_pos = + if let Some(new_pos) = lsp_pos_to_pos(doc.text(), definition_pos, offset_encoding) { + new_pos + } else { + return; + }; doc.set_selection(view.id, Selection::point(new_pos)); align_view(doc, view, Align::Center); } @@ -2297,11 +2302,7 @@ pub fn completion(cx: &mut Context) { let offset_encoding = language_server.offset_encoding(); - let pos = pos_to_lsp_pos( - doc.text(), - doc.selection(view.id).cursor(), - language_server.offset_encoding(), - ); + let pos = pos_to_lsp_pos(doc.text(), doc.selection(view.id).cursor(), offset_encoding); // TODO: handle fails let future = language_server.completion(doc.identifier(), pos); |