Parse the declaration after the trigger to extract parameter names, type hints, return types, etc.
(text: &str)
| 599 | /// Parse the declaration after the trigger to extract parameter names, |
| 600 | /// type hints, return types, etc. |
| 601 | fn 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 |