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

Function kt_process_function_decl

internal/cbm/lsp/kotlin_lsp.c:2082–2136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2080}
2081
2082static void kt_process_function_decl(KotlinLSPContext *ctx, TSNode node) {
2083 TSNode name = kt_field_named(node, "name");
2084 if (ts_node_is_null(name)) {
2085 name = kt_name_child(node);
2086 }
2087 if (ts_node_is_null(name)) {
2088 return;
2089 }
2090 char *fname = kt_node_text(ctx, name);
2091 if (!fname) {
2092 return;
2093 }
2094 /* Detect extension function via the new helper which walks children
2095 * for a type-shaped node preceding the name. Handles the inlined
2096 * `_receiver_type` rule that tree-sitter doesn't expose as a named
2097 * child. */
2098 char *recv_text = NULL;
2099 TSNode receiver = kt_find_extension_receiver(ctx, node, name, &recv_text);
2100 (void)receiver;
2101 if (recv_text) {
2102 char *lt = strchr(recv_text, '<');
2103 if (lt) {
2104 *lt = '\0';
2105 }
2106 size_t rlen = strlen(recv_text);
2107 while (rlen > 0 && (recv_text[rlen - 1] == '?' || recv_text[rlen - 1] == ' ' ||
2108 recv_text[rlen - 1] == '\t' || recv_text[rlen - 1] == '\n')) {
2109 recv_text[--rlen] = '\0';
2110 }
2111 }
2112
2113 CBMRegisteredFunc rf = {0};
2114 rf.short_name = fname;
2115 rf.min_params = 0;
2116
2117 if (recv_text && *recv_text) {
2118 const char *recv_qn = kotlin_resolve_class_name(ctx, recv_text);
2119 rf.receiver_type = recv_qn;
2120 rf.qualified_name = kt_join_dot(ctx->arena, ctx->package_qn, fname);
2121 } else if (ctx->enclosing_class_qn) {
2122 rf.receiver_type = ctx->enclosing_class_qn;
2123 rf.qualified_name = kt_join_dot(ctx->arena, ctx->enclosing_class_qn, fname);
2124 } else {
2125 rf.qualified_name = kt_join_dot(ctx->arena, ctx->package_qn, fname);
2126 }
2127 const CBMType **param_types = kt_signature_param_types_from_ast(ctx, node);
2128 const CBMType *return_type = NULL;
2129 /* Capture return type for chain tracking. */
2130 TSNode rt_node = kt_find_return_type(node);
2131 if (!ts_node_is_null(rt_node)) {
2132 return_type = kotlin_parse_type_node(ctx, rt_node);
2133 }
2134 rf.signature = kt_build_func_sig_with_return(ctx, param_types, return_type);
2135 cbm_registry_add_func((CBMTypeRegistry *)ctx->registry, rf);
2136}
2137
2138static void kt_process_property_decl(KotlinLSPContext *ctx, TSNode node) {
2139 /* property_declaration: ('val'|'var') variable_declaration ('=' expr)? */

Callers 1

Calls 11

kt_field_namedFunction · 0.85
kt_name_childFunction · 0.85
kt_node_textFunction · 0.85
kt_join_dotFunction · 0.85
kt_find_return_typeFunction · 0.85
kotlin_parse_type_nodeFunction · 0.85
cbm_registry_add_funcFunction · 0.85

Tested by

no test coverage detected