Build an LSP snippet string for a callable (function, method, or constructor). Required parameters are included as numbered tab stops with their PHP variable name as placeholder text. Optional and variadic parameters are omitted — they can be filled in via signature help. The returned string uses LSP snippet syntax and **must** be paired with `InsertTextFormat::SNIPPET` on the `CompletionItem`.
(name: &str, params: &[ParameterInfo])
| 54 | /// | `("makeText", &[req($text), opt($long)])` | `"makeText(${1:\\$text})$0"` | |
| 55 | /// | `("add", &[req($a), req($b)])` | `"add(${1:\\$a}, ${2:\\$b})$0"` | |
| 56 | pub(crate) fn build_callable_snippet(name: &str, params: &[ParameterInfo]) -> String { |
| 57 | let required: Vec<&ParameterInfo> = params.iter().filter(|p| p.is_required).collect(); |
| 58 | |
| 59 | if required.is_empty() { |
| 60 | format!("{name}()$0") |
| 61 | } else { |
| 62 | let placeholders: Vec<String> = required |
| 63 | .iter() |
| 64 | .enumerate() |
| 65 | .map(|(i, p)| { |
| 66 | // Escape `$` in parameter names so it is treated as a |
| 67 | // literal character rather than a snippet tab-stop / |
| 68 | // variable reference. |
| 69 | let escaped_name = p.name.replace('$', "\\$"); |
| 70 | format!("${{{}:{}}}", i + 1, escaped_name) |
| 71 | }) |
| 72 | .collect(); |
| 73 | format!("{name}({})$0", placeholders.join(", ")) |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /// Build an LSP snippet string for a PHP attribute constructor. |
| 78 | /// |
no test coverage detected