Prevent underflow when converting line numbers
Previously, when line numbers of Rust spans were converted to LSP
ranges, they could underflow resulting in very large line numbers. As
an underflow is always wrong, prevent it and use 0 instead.
@@ -63,8 +63,14 @@ fn location(
// FIXME: this doesn't handle UTF16 offsets correctly
let range = lsp_types::Range::new(
- lsp_types::Position::new(span.line_start as u32 - 1, span.column_start as u32 - 1),
- lsp_types::Position::new(span.line_end as u32 - 1, span.column_end as u32 - 1),
+ lsp_types::Position::new(
+ (span.line_start as u32).saturating_sub(1),
+ (span.column_start as u32).saturating_sub(1),
+ ),
+ lsp_types::Position::new(
+ (span.line_end as u32).saturating_sub(1),
+ (span.column_end as u32).saturating_sub(1),
+ ),
);
lsp_types::Location { uri, range }
