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

Function extract_named_arg_name

src/completion/named_args.rs:458–489  ·  view source on GitHub ↗

If `arg` looks like a named argument (`name: ...`), return the name. Returns `None` for positional arguments.

(arg: &str)

Source from the content-addressed store, hash-verified

456/// If `arg` looks like a named argument (`name: ...`), return the name.
457/// Returns `None` for positional arguments.
458pub fn extract_named_arg_name(arg: &str) -> Option<String> {
459 // Look for `identifier:` at the start (but not `::`)
460 let chars: Vec<char> = arg.chars().collect();
461 let mut i = 0;
462
463 // Skip whitespace
464 while i < chars.len() && chars[i].is_whitespace() {
465 i += 1;
466 }
467
468 // Read identifier
469 let start = i;
470 while i < chars.len() && (chars[i].is_alphanumeric() || chars[i] == '_') {
471 i += 1;
472 }
473
474 if i == start {
475 return None;
476 }
477
478 // Must be followed by `:` (but not `::`)
479 if i < chars.len() && chars[i] == ':' {
480 // Check it's not `::`
481 if i + 1 < chars.len() && chars[i + 1] == ':' {
482 return None;
483 }
484 let name: String = chars[start..i].iter().collect();
485 return Some(name);
486 }
487
488 None
489}
490
491// ─── Completion Builder ─────────────────────────────────────────────────────
492

Callers 1

parse_existing_argsFunction · 0.85

Calls 1

iterMethod · 0.80

Tested by

no test coverage detected