Mirror extract_calls.c's terminal_callee_leaf policy so the PHP LSP and * USAGE passes attach the same exact token occurrence to a first-class * callable, including qualified free-function references. */
| 1367 | * USAGE passes attach the same exact token occurrence to a first-class |
| 1368 | * callable, including qualified free-function references. */ |
| 1369 | static TSNode php_reference_callee_leaf(PHPLSPContext *ctx, TSNode expr) { |
| 1370 | static const char *const terminal_fields[] = {"property", "field", "attribute", |
| 1371 | "method", "name", NULL}; |
| 1372 | /* A loop for the same reason as terminal_callee_leaf: recursing once per |
| 1373 | * wrapper level of the callee made stack use follow the nesting depth of |
| 1374 | * the file. Same nodes, same order. */ |
| 1375 | for (;;) { |
| 1376 | if (ts_node_is_null(expr) || php_dynamic_reference_expr(ctx, expr)) { |
| 1377 | return (TSNode){0}; |
| 1378 | } |
| 1379 | |
| 1380 | TSNode terminal = {0}; |
| 1381 | for (int i = 0; terminal_fields[i] && ts_node_is_null(terminal); i++) { |
| 1382 | terminal = ts_node_child_by_field_name(expr, terminal_fields[i], |
| 1383 | (uint32_t)strlen(terminal_fields[i])); |
| 1384 | } |
| 1385 | if (!ts_node_is_null(terminal)) { |
| 1386 | expr = terminal; |
| 1387 | continue; |
| 1388 | } |
| 1389 | |
| 1390 | const char *kind = ts_node_type(expr); |
| 1391 | if (strcmp(kind, "identifier") == 0 || strcmp(kind, "simple_identifier") == 0 || |
| 1392 | strcmp(kind, "type_identifier") == 0 || strcmp(kind, "field_identifier") == 0 || |
| 1393 | strcmp(kind, "property_identifier") == 0 || strcmp(kind, "name") == 0 || |
| 1394 | strcmp(kind, "variable_name") == 0 || strcmp(kind, "attribute") == 0 || |
| 1395 | strcmp(kind, "symbol") == 0 || strcmp(kind, "sym_lit") == 0 || |
| 1396 | strcmp(kind, "user_symbol") == 0) { |
| 1397 | return expr; |
| 1398 | } |
| 1399 | |
| 1400 | uint32_t count = ts_node_named_child_count(expr); |
| 1401 | if (count == 0) { |
| 1402 | return (TSNode){0}; |
| 1403 | } |
| 1404 | bool terminal_is_last = strstr(kind, "qualified") || strstr(kind, "scoped") || |
| 1405 | strstr(kind, "member") || strstr(kind, "selector") || |
| 1406 | strstr(kind, "navigation") || strstr(kind, "field_expression"); |
| 1407 | expr = ts_node_named_child(expr, terminal_is_last ? count - 1 : 0); |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | static TSNode php_callable_reference_leaf(PHPLSPContext *ctx, TSNode call, const char *kind) { |
| 1412 | if (php_callable_reference_has_dynamic_member_name(ctx, call)) { |
no test coverage detected