mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
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.
This commit is contained in:
parent
a1d684e951
commit
a98ffe4268
1 changed files with 8 additions and 2 deletions
|
@ -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 }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue