If `arg` looks like a named argument (`name: ...`), return the name. Returns `None` for positional arguments.
(arg: &str)
| 456 | /// If `arg` looks like a named argument (`name: ...`), return the name. |
| 457 | /// Returns `None` for positional arguments. |
| 458 | pub 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 |
no test coverage detected