@@ -2221,3 +2221,58 @@ function getTimeout(): int
22212221if (MAX_RETRIES > 0 ) { // → jumps to define('MAX_RETRIES', ...)
22222222 echo APP_VERSION ; // → jumps to define('APP_VERSION', ...)
22232223}
2224+
2225+ // ─── Callable Snippet Insertion ─────────────────────────────────────────────
2226+ //
2227+ // When completing methods, functions, or `new ClassName`, the LSP inserts
2228+ // a snippet with parentheses and tab-stops for each **required** parameter.
2229+ // Optional and variadic parameters are omitted — use signature help to
2230+ // fill those in.
2231+ //
2232+ // Method examples:
2233+ // $user->setName(|) — setName(string $name) → snippet: setName(${1:\$name})
2234+ // $user->toArray() — toArray() has no params → snippet: toArray()
2235+ // $user->addRoles(|) — addRoles(string ...$roles) variadic → snippet: addRoles()
2236+ //
2237+ // Function examples:
2238+ // createUser(|) — createUser(string $name, …) → snippet: createUser(${1:\$name})
2239+ // Built-in stubs like json_decode get empty parens: json_decode()
2240+ //
2241+ // `new ClassName` examples (same-namespace classes get full constructor params):
2242+ // new User(|,|) — __construct(string $name, string $email) → User(${1:\$name}, ${2:\$email})
2243+ // new Response(|) — __construct(int $statusCode, …) → Response(${1:\$statusCode})
2244+ // Classes from classmap/stubs just get empty parens: new DateTime()
2245+
2246+ class CallableSnippetDemo
2247+ {
2248+ public function methodSnippets (User $ user , Response $ response ): void
2249+ {
2250+ // Try completing after `->` — each inserts a snippet with required params:
2251+ $ user ->setName ($ name ); // Inserted: setName(${1:$name}) — 1 required param
2252+ $ user ->toArray (); // Inserted: toArray() — no params
2253+ $ user ->addRoles (); // Inserted: addRoles() — variadic only
2254+ $ response ->getBody (); // Inserted: getBody() — no params
2255+ }
2256+
2257+ public function staticSnippets (): void
2258+ {
2259+ // Static method calls also get snippets:
2260+ User::findByEmail ($ email ); // Inserted: findByEmail(${1:$email}) — 1 required param
2261+ Model::find ($ id ); // Inserted: find(${1:$id}) — 1 required param
2262+ }
2263+
2264+ public function newSnippets (): void
2265+ {
2266+ // `new` inserts class name + constructor params as snippet:
2267+ $ u = new User($ name , $ email ) // Inserted: User(${1:$name}, ${2:$email}) — 2 required
2268+ $ r = new Response ($ statusCode ); // Inserted: Response(${1:$statusCode}) — 1 required
2269+ $ a = new AdminUser ($ name , $ email ); // Inserted: AdminUser(${1:$name}, ${2:$email}, ${3:$role})
2270+ }
2271+
2272+ public function parentConstructorSnippet (): void
2273+ {
2274+ // parent::__construct also gets snippets when inside a subclass.
2275+ // See AdminUser::__construct for an example:
2276+ // parent::__construct(${1:$name}, ${2:$email})
2277+ }
2278+ }
0 commit comments