Build a diagnostic range from byte offsets, returning `None` if either offset is past the end of `content`. This thin wrapper around [`crate::util::byte_range_to_lsp_range`] adds a bounds check so that stale byte offsets (e.g. from a previous AST after an edit) are rejected instead of silently clamped to EOF.
(
content: &str,
start_byte: usize,
end_byte: usize,
)
| 2063 | /// a bounds check so that stale byte offsets (e.g. from a previous AST |
| 2064 | /// after an edit) are rejected instead of silently clamped to EOF. |
| 2065 | pub(crate) fn offset_range_to_lsp_range( |
| 2066 | content: &str, |
| 2067 | start_byte: usize, |
| 2068 | end_byte: usize, |
| 2069 | ) -> Option<Range> { |
| 2070 | if start_byte > content.len() || end_byte > content.len() { |
| 2071 | return None; |
| 2072 | } |
| 2073 | Some(crate::util::byte_range_to_lsp_range( |
| 2074 | content, start_byte, end_byte, |
| 2075 | )) |
| 2076 | } |
| 2077 | |
| 2078 | // ── Tests ─────────────────────────────────────────────────────────────────── |
| 2079 |
no test coverage detected