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

Function extract_simple_variable

src/subject_extraction.rs:628–647  ·  view source on GitHub ↗

Extract a simple `$variable` or bare identifier ending at position `end` (exclusive). Skips trailing whitespace, then walks backwards through identifier characters. If a `$` prefix is found, includes it (producing e.g. `"$this"`, `"$var"`). Otherwise returns whatever identifier was collected (e.g. `"self"`, `"parent"`), which may be empty.

(chars: &[char], end: usize)

Source from the content-addressed store, hash-verified

626/// `"$this"`, `"$var"`). Otherwise returns whatever identifier was
627/// collected (e.g. `"self"`, `"parent"`), which may be empty.
628fn extract_simple_variable(chars: &[char], end: usize) -> String {
629 let mut i = end;
630 // skip whitespace
631 while i > 0 && chars[i - 1] == ' ' {
632 i -= 1;
633 }
634 let var_end = i;
635 // walk back through identifier chars
636 while i > 0 && (chars[i - 1].is_alphanumeric() || chars[i - 1] == '_') {
637 i -= 1;
638 }
639 // expect `$` prefix
640 if i > 0 && chars[i - 1] == '$' {
641 i -= 1;
642 chars[i..var_end].iter().collect()
643 } else {
644 // no `$` — return whatever we collected (may be empty)
645 chars[i..var_end].iter().collect()
646 }
647}
648
649/// Extract the identifier/keyword before `::`.
650///

Callers 2

extract_arrow_subjectFunction · 0.85
extract_call_subjectFunction · 0.85

Calls 1

iterMethod · 0.80

Tested by

no test coverage detected