MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / extract_handler_arg

Function extract_handler_arg

internal/cbm/extract_calls.c:3124–3166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3122}
3123
3124static const char *extract_handler_arg(CBMExtractCtx *ctx, TSNode args) {
3125 /* The LAST eligible argument wins, and every argument is examined.
3126 * Express, Fastify, gin and Laravel all put middleware between the route
3127 * path and the handler, so the first function-shaped argument is usually a
3128 * middleware. Taking the first one pointed the HANDLES edge at the
3129 * middleware; stopping the scan early missed the handler outright when the
3130 * middleware was written inline, because an arrow function matches none of
3131 * the kinds below. Nothing that follows a handler matches them either — an
3132 * options argument is an object node — so the last match is the handler. */
3133 const char *handler = NULL;
3134 uint32_t nc = ts_node_named_child_count(args);
3135 for (uint32_t ai = HANDLER_START_IDX; ai < nc; ai++) {
3136 TSNode arg2 = ts_node_named_child(args, ai);
3137 /* PHP wraps each argument in an `argument` node — unwrap to the value. */
3138 if (strcmp(ts_node_type(arg2), "argument") == 0 && ts_node_named_child_count(arg2) > 0) {
3139 arg2 = ts_node_named_child(arg2, 0);
3140 }
3141 if (ctx->language == CBM_LANG_PHP) {
3142 const char *class_handler = php_class_route_handler(ctx, arg2);
3143 if (class_handler) {
3144 handler = class_handler;
3145 continue;
3146 }
3147 }
3148 const char *ak2 = ts_node_type(arg2);
3149 /* `name` = PHP bare identifier handler; string = Laravel string handler
3150 * ('showUsers' or 'Controller@method'). */
3151 if (strcmp(ak2, "identifier") == 0 || strcmp(ak2, "member_expression") == 0 ||
3152 strcmp(ak2, "selector_expression") == 0 || strcmp(ak2, "attribute") == 0 ||
3153 strcmp(ak2, "field_expression") == 0 || strcmp(ak2, "name") == 0) {
3154 handler = cbm_node_text(ctx->arena, arg2, ctx->source);
3155 continue;
3156 }
3157 if (is_string_like(ak2)) {
3158 const char *h =
3159 normalize_string_handler(ctx->arena, cbm_node_text(ctx->arena, arg2, ctx->source));
3160 if (h && h[0]) {
3161 handler = h;
3162 }
3163 }
3164 }
3165 return handler;
3166}
3167
3168// Extract JSX component refs (uppercase tags) as CALLS edges.
3169static void extract_jsx_component_ref(CBMExtractCtx *ctx, TSNode node, const char *kind,

Callers 1

handle_callsFunction · 0.85

Calls 4

php_class_route_handlerFunction · 0.85
cbm_node_textFunction · 0.85
is_string_likeFunction · 0.85
normalize_string_handlerFunction · 0.85

Tested by

no test coverage detected