summaryrefslogtreecommitdiff
path: root/helix-term/src/application.rs
diff options
context:
space:
mode:
authorWojciech Kępka2021-06-12 07:04:30 +0000
committerGitHub2021-06-12 07:04:30 +0000
commitc754df12b38595b29575e7b58911386a16ac9951 (patch)
treeba6beaaa96796f413a9d7e26711c1222b8e0d309 /helix-term/src/application.rs
parent1bf5b103b00f056ebd012831e3ad7b00d752d566 (diff)
lsp: Check bounds when converting lsp positions (#204)
* lsp: Make position conversion funcs return `Option` * Add tests * Fixes * Revert pos_to_lsp_pos to panic
Diffstat (limited to 'helix-term/src/application.rs')
-rw-r--r--helix-term/src/application.rs25
1 files changed, 18 insertions, 7 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();