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

Function build_callable_snippet

src/completion/builder.rs:56–75  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

54/// | `("makeText", &[req($text), opt($long)])` | `"makeText(${1:\\$text})$0"` |
55/// | `("add", &[req($a), req($b)])` | `"add(${1:\\$a}, ${2:\\$b})$0"` |
56pub(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///

Callers 4

build_completion_itemsFunction · 0.85
build_new_insertMethod · 0.85

Calls 4

filterMethod · 0.80
iterMethod · 0.80
is_emptyMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected