pub fn extract_context_safe(
source: &[u8],
byte_start: usize,
byte_end: usize,
context_bytes: usize,
) -> Option<String>Expand description
Safely extract context lines from source bytes around a byte span
Similar to extract_symbol_content_safe, but extracts context around
a span rather than the span itself. This is useful for extracting
surrounding lines for better context in code intelligence tools.
§Arguments
source- Source file contents as bytesbyte_start- Start byte offset of the span (inclusive)byte_end- End byte offset of the span (exclusive)context_bytes- Number of additional bytes to extract before and after
§Returns
Some(String) with the extracted context, or None if extraction fails
§Example
let source = "line1\nline2\nline3\nline4";
let context = extract_context_safe(source.as_bytes(), 7, 13, 5);
// Extracts around "line2" with 5 bytes of context