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

Function parse_params

src/completion/phpdoc/generation.rs:769–825  ·  view source on GitHub ↗

Parse a comma-separated parameter list into `(type_hint, $name)` pairs.

(params_str: &str)

Source from the content-addressed store, hash-verified

767
768/// Parse a comma-separated parameter list into `(type_hint, $name)` pairs.
769fn parse_params(params_str: &str) -> Vec<(Option<PhpType>, String)> {
770 if params_str.trim().is_empty() {
771 return Vec::new();
772 }
773
774 let mut result = Vec::new();
775
776 for param in split_params(params_str) {
777 let param = param.trim();
778 if param.is_empty() {
779 continue;
780 }
781
782 // Each param looks like: [Type] [$name] [= default]
783 // or: [Type] &$name, [Type] ...$name
784 let tokens: Vec<&str> = param.split_whitespace().collect();
785
786 // Find the variable name token (starts with $, &$, or ...$).
787 let mut var_name = None;
788 let mut type_parts = Vec::new();
789
790 for tok in &tokens {
791 if tok.starts_with('$') || tok.starts_with("&$") || tok.starts_with("...$") {
792 let name = tok.trim_start_matches('&').trim_start_matches("...");
793 // Strip default value.
794 let name = if let Some(eq) = name.find('=') {
795 name[..eq].trim()
796 } else {
797 name
798 };
799 var_name = Some(name.to_string());
800 break;
801 }
802 // Skip `=` and default values.
803 if *tok == "=" {
804 break;
805 }
806 // Skip constructor promotion modifiers.
807 match tok.to_lowercase().as_str() {
808 "public" | "protected" | "private" | "static" | "readonly" => continue,
809 _ => {}
810 }
811 type_parts.push(*tok);
812 }
813
814 if let Some(name) = var_name {
815 let type_hint = if type_parts.is_empty() {
816 None
817 } else {
818 Some(PhpType::parse(&type_parts.join(" ")))
819 };
820 result.push((type_hint, name));
821 }
822 }
823
824 result
825}
826

Callers 1

parse_declaration_infoFunction · 0.70

Calls 5

as_strMethod · 0.80
pushMethod · 0.80
split_paramsFunction · 0.70
is_emptyMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected