MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / offset_range_to_lsp_range

Function offset_range_to_lsp_range

src/diagnostics/mod.rs:2065–2076  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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.
2065pub(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

Callers 1

Calls 1

byte_range_to_lsp_rangeFunction · 0.85

Tested by

no test coverage detected