@@ -219,6 +219,57 @@ impl Backend {
219219 }
220220 }
221221
222+ // ── Type hint completion in definitions ─────────────────
223+ // When the cursor is at a type-hint position inside a
224+ // function/method parameter list, return type, or property
225+ // declaration, offer PHP native scalar types alongside
226+ // class-name completions (but NOT constants or standalone
227+ // functions, which are invalid in type positions).
228+ //
229+ // This check MUST run before named-argument detection so
230+ // that typing inside a function *definition* like
231+ // `function foo(Us|)` offers type completions rather than
232+ // named-argument suggestions for a same-named function.
233+ if let Some ( th_ctx) = crate :: completion:: type_hint_completion:: detect_type_hint_context (
234+ & content, position,
235+ ) {
236+ let partial_lower = th_ctx. partial . to_lowercase ( ) ;
237+ let mut items: Vec < CompletionItem > =
238+ crate :: completion:: type_hint_completion:: PHP_NATIVE_TYPES
239+ . iter ( )
240+ . filter ( |t| t. to_lowercase ( ) . starts_with ( & partial_lower) )
241+ . enumerate ( )
242+ . map ( |( idx, t) | CompletionItem {
243+ label : t. to_string ( ) ,
244+ kind : Some ( CompletionItemKind :: KEYWORD ) ,
245+ detail : Some ( "PHP built-in type" . to_string ( ) ) ,
246+ insert_text : Some ( t. to_string ( ) ) ,
247+ filter_text : Some ( t. to_string ( ) ) ,
248+ sort_text : Some ( format ! ( "0_{:03}" , idx) ) ,
249+ ..CompletionItem :: default ( )
250+ } )
251+ . collect ( ) ;
252+
253+ let ( class_items, class_incomplete) = self . build_class_name_completions (
254+ & file_use_map,
255+ & file_namespace,
256+ & th_ctx. partial ,
257+ & content,
258+ false , // not a `new` context
259+ ) ;
260+ items. extend ( class_items) ;
261+
262+ if !items. is_empty ( ) {
263+ return Ok ( Some ( CompletionResponse :: List ( CompletionList {
264+ is_incomplete : class_incomplete,
265+ items,
266+ } ) ) ) ;
267+ }
268+ // Even when empty, return early so we don't fall through
269+ // to named-arg or class+constant+function completion.
270+ return Ok ( None ) ;
271+ }
272+
222273 // ── Named argument completion ───────────────────────────
223274 // When the cursor is inside the parentheses of a function or
224275 // method call, offer parameter names as `name:` completions.
0 commit comments