| 1312 | /// Parameter names within the `@param` block are space-aligned. |
| 1313 | #[allow(clippy::too_many_arguments)] |
| 1314 | fn build_function_snippet( |
| 1315 | sym: &SymbolInfo, |
| 1316 | _indent: &str, |
| 1317 | content: &str, |
| 1318 | position: Position, |
| 1319 | use_map: &HashMap<String, String>, |
| 1320 | file_namespace: &Option<String>, |
| 1321 | local_classes: &[Arc<ClassInfo>], |
| 1322 | class_loader: &dyn Fn(&str) -> Option<Arc<ClassInfo>>, |
| 1323 | function_loader: FunctionLoader<'_>, |
| 1324 | ) -> String { |
| 1325 | let throws_ctx = ThrowsContext { |
| 1326 | class_loader, |
| 1327 | function_loader, |
| 1328 | use_map, |
| 1329 | file_namespace, |
| 1330 | }; |
| 1331 | let uncaught = throws_analysis::find_uncaught_throw_types_with_context( |
| 1332 | content, |
| 1333 | position, |
| 1334 | Some(&throws_ctx), |
| 1335 | ); |
| 1336 | |
| 1337 | let mut tab_stop = 1u32; |
| 1338 | |
| 1339 | // Collect @param tags that need enrichment. |
| 1340 | // Each entry is (snippet_type, display_len, escaped_name). |
| 1341 | let mut param_tags: Vec<(String, usize, String)> = Vec::new(); |
| 1342 | for (type_hint, name) in &sym.params { |
| 1343 | if let Some(enriched) = enrichment_snippet(type_hint.as_ref(), &mut tab_stop, class_loader) |
| 1344 | { |
| 1345 | // Use the plain-text version to measure the rendered width for |
| 1346 | // alignment. The snippet version contains `${N:...}` markers |
| 1347 | // that inflate its length. |
| 1348 | let display_len = enrichment_plain(type_hint.as_ref(), class_loader) |
| 1349 | .map(|p| p.len()) |
| 1350 | .unwrap_or(enriched.len()); |
| 1351 | // Escape `$` in PHP parameter names so the snippet parser |
| 1352 | // does not treat them as snippet variables. |
| 1353 | param_tags.push((enriched, display_len, name.replace('$', "\\$"))); |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | // Determine @return enrichment. |
| 1358 | // Constructors never get @return (they implicitly return the class). |
| 1359 | let is_constructor = sym |
| 1360 | .method_name |
| 1361 | .as_ref() |
| 1362 | .is_some_and(|n| n.eq_ignore_ascii_case("__construct")); |
| 1363 | let is_void = sym.return_type.as_ref().is_some_and(|r| r.is_void()); |
| 1364 | let return_tag = if is_void || is_constructor { |
| 1365 | None |
| 1366 | } else { |
| 1367 | // Try body-based inference first (produces richer types like |
| 1368 | // `list<string>` instead of `array<mixed>`). |
| 1369 | let body_inferred = crate::code_actions::phpstan::fix_return_type::enrichment_return_type( |
| 1370 | content, |
| 1371 | position, |