Unnamed repository; edit this file 'description' to name the repository.
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.
| -rw-r--r-- | crates/rust-analyzer/src/diagnostics/to_proto.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs index dd59923cb3..9d229c36f5 100644 --- a/crates/rust-analyzer/src/diagnostics/to_proto.rs +++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs @@ -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 } |