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

Function count_trailing_close_chars

src/completion/array_shape.rs:620–652  ·  view source on GitHub ↗

Count the number of trailing auto-inserted characters after the cursor. When the IDE auto-closes brackets, the line may contain: - `']` or `"]` after the cursor (2 chars) — when a quote was typed - `]` after the cursor (1 char) — when only `[` was typed This function looks at the characters starting at `cursor_col` and returns how many should be consumed by the text edit range.

(
    chars: &[char],
    cursor_col: usize,
    quote_char: Option<char>,
)

Source from the content-addressed store, hash-verified

618/// This function looks at the characters starting at `cursor_col` and
619/// returns how many should be consumed by the text edit range.
620fn count_trailing_close_chars(
621 chars: &[char],
622 cursor_col: usize,
623 quote_char: Option<char>,
624) -> usize {
625 if cursor_col >= chars.len() {
626 return 0;
627 }
628
629 let remaining = &chars[cursor_col..];
630
631 match quote_char {
632 Some(q) => {
633 // Expect closing quote + `]`
634 if remaining.len() >= 2 && remaining[0] == q && remaining[1] == ']' {
635 2
636 } else if !remaining.is_empty() && remaining[0] == ']' {
637 // Just a `]` even though we had a quote — still consume it
638 1
639 } else {
640 0
641 }
642 }
643 None => {
644 // Expect just `]`
645 if !remaining.is_empty() && remaining[0] == ']' {
646 1
647 } else {
648 0
649 }
650 }
651 }
652}
653
654/// Extract spread expressions from an array literal.
655///

Callers 1

compute_edit_rangeMethod · 0.85

Calls 1

is_emptyMethod · 0.45

Tested by

no test coverage detected