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

Method offset_range_to_lsp_range

src/diagnostics/mod.rs:2019–2056  ·  view source on GitHub ↗

Convert a byte range from the preprocessed (virtual) content back to an LSP range in the original source file. For standard PHP files, this is a straight conversion. For Blade files, it converts the bytes to positions in the virtual PHP, then translates those positions back to original Blade coordinates using the source map.

(
        &self,
        uri: &str,
        content: &str,
        start_byte: usize,
        end_byte: usize,
    )

Source from the content-addressed store, hash-verified

2017 /// translates those positions back to original Blade coordinates using
2018 /// the source map.
2019 pub(crate) fn offset_range_to_lsp_range(
2020 &self,
2021 uri: &str,
2022 content: &str,
2023 start_byte: usize,
2024 end_byte: usize,
2025 ) -> Option<Range> {
2026 let virtual_php_handle = self.blade_virtual_content.read();
2027 if let Some(virtual_php) = virtual_php_handle.get(uri)
2028 && let Some(map) = self.blade_source_maps.read().get(uri)
2029 {
2030 if start_byte > virtual_php.len() || end_byte > virtual_php.len() {
2031 return None;
2032 }
2033
2034 let mut range = crate::util::byte_range_to_lsp_range(virtual_php, start_byte, end_byte);
2035
2036 if range.start.line < crate::blade::PROLOGUE_LINES {
2037 // Diagnostic originates from the prologue (injected headers).
2038 // We skip these to avoid false positives on line 1 of Blade.
2039 return None;
2040 }
2041
2042 range.start = map.php_to_blade(range.start);
2043 range.end = map.php_to_blade(range.end);
2044
2045 return Some(range);
2046 }
2047
2048 // Fallback for standard PHP or if map is missing
2049 if start_byte > content.len() || end_byte > content.len() {
2050 return None;
2051 }
2052
2053 Some(crate::util::byte_range_to_lsp_range(
2054 content, start_byte, end_byte,
2055 ))
2056 }
2057}
2058
2059/// Build a diagnostic range from byte offsets, returning `None` if either

Calls 3

byte_range_to_lsp_rangeFunction · 0.85
php_to_bladeMethod · 0.80
getMethod · 0.45