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

Function parse_declaration_info

src/completion/phpdoc/generation.rs:601–690  ·  view source on GitHub ↗

Parse the declaration after the trigger to extract parameter names, type hints, return types, etc.

(text: &str)

Source from the content-addressed store, hash-verified

599/// Parse the declaration after the trigger to extract parameter names,
600/// type hints, return types, etc.
601fn parse_declaration_info(text: &str) -> SymbolInfo {
602 // Reuse the existing parser from the context module, but we need
603 // to work from the raw text directly.
604 let mut info = SymbolInfo::default();
605
606 // Collect the declaration — may span multiple lines until `{` or `;`.
607 let mut decl = String::new();
608 let mut attr_depth = 0i32;
609 for line in text.lines() {
610 let trimmed = line.trim();
611 if trimmed.is_empty() {
612 continue;
613 }
614 if trimmed.starts_with('*') || trimmed.starts_with("/**") {
615 continue;
616 }
617 // Skip PHP 8 attribute lines (#[...]). Track bracket nesting
618 // depth so that array literals inside attributes don't
619 // prematurely end tracking.
620 if attr_depth > 0 || trimmed.starts_with("#[") {
621 for ch in trimmed.chars() {
622 match ch {
623 '[' => attr_depth += 1,
624 ']' => attr_depth -= 1,
625 _ => {}
626 }
627 }
628 continue;
629 }
630 decl.push(' ');
631 decl.push_str(trimmed);
632 if trimmed.contains('{') || trimmed.contains(';') {
633 break;
634 }
635 }
636
637 let decl = decl.trim();
638 if decl.is_empty() {
639 return info;
640 }
641
642 // Check if it's a function/method.
643 if let Some(func_pos) = find_keyword_pos(decl, "function") {
644 let after_func = &decl[func_pos + 8..].trim_start();
645
646 // Extract the method/function name (skip leading `&` for references).
647 let name_src = after_func
648 .strip_prefix('&')
649 .unwrap_or(after_func)
650 .trim_start();
651 let name: String = name_src
652 .chars()
653 .take_while(|c| c.is_alphanumeric() || *c == '_')
654 .collect();
655 if !name.is_empty() {
656 info.method_name = Some(name);
657 }
658

Callers 15

try_generate_docblockFunction · 0.85
parses_params_with_typesFunction · 0.85
parses_nullable_typeFunction · 0.85
parses_union_typeFunction · 0.85
parses_variadic_paramFunction · 0.85
parses_reference_paramFunction · 0.85
parses_no_paramsFunction · 0.85
parses_property_typeFunction · 0.85

Calls 11

find_keyword_posFunction · 0.85
is_class_like_keywordFunction · 0.85
extract_class_supertypesFunction · 0.85
pushMethod · 0.80
containsMethod · 0.80
find_matching_parenFunction · 0.70
parse_paramsFunction · 0.70
extract_property_typeFunction · 0.70
is_emptyMethod · 0.45
findMethod · 0.45