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

Method compute_edit_range

src/completion/array_shape.rs:447–476  ·  view source on GitHub ↗

Compute the `TextEdit` range for an array key completion. The range starts at `key_start_col` (right after the opening quote or `[`) and extends past any trailing auto-inserted characters (closing quote + `]`) that the IDE may have inserted. Returns `(range, trailing_count)` where `trailing_count` is the number of characters consumed after the cursor.

(
        &self,
        ctx: &ArrayKeyContext,
        content: &str,
        position: Position,
    )

Source from the content-addressed store, hash-verified

445 /// Returns `(range, trailing_count)` where `trailing_count` is the
446 /// number of characters consumed after the cursor.
447 fn compute_edit_range(
448 &self,
449 ctx: &ArrayKeyContext,
450 content: &str,
451 position: Position,
452 ) -> (Range, usize) {
453 let lines: Vec<&str> = content.lines().collect();
454 let line_idx = position.line as usize;
455 let trailing_count = if line_idx < lines.len() {
456 let line = lines[line_idx];
457 let chars: Vec<char> = line.chars().collect();
458 let cursor_col = position.character as usize;
459 count_trailing_close_chars(&chars, cursor_col, ctx.quote_char)
460 } else {
461 0
462 };
463
464 let range = Range {
465 start: Position {
466 line: position.line,
467 character: ctx.key_start_col,
468 },
469 end: Position {
470 line: position.line,
471 character: position.character + trailing_count as u32,
472 },
473 };
474
475 (range, trailing_count)
476 }
477
478 /// Walk through `prefix_keys` to resolve the inner type of a nested
479 /// array shape.

Callers 2

Calls 1

Tested by

no test coverage detected