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

Function kt_process_lambda

internal/cbm/lsp/kotlin_lsp.c:3802–3856  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3800}
3801
3802static void kt_process_lambda(KotlinLSPContext *ctx, TSNode lambda, const CBMType *receiver_type) {
3803 /* lambda_literal: '{' lambda_parameters? '->' statements '}'
3804 * If no parameters, `it` is bound to the receiver. */
3805 if (ts_node_is_null(lambda)) {
3806 return;
3807 }
3808 ctx->current_scope = cbm_scope_push(ctx->arena, ctx->current_scope);
3809 const CBMType *prev_it = ctx->it_type;
3810 /* DSL receiver: when the callee's lambda parameter has a function-with-
3811 * receiver type (`Foo.() -> Unit`), the lambda's `this` is Foo and bare
3812 * calls inside resolve against Foo's members. The dsl_this_type is
3813 * passed via receiver_type when the caller can determine it. */
3814 const CBMType *prev_this = ctx->this_type;
3815 if (receiver_type && !cbm_type_is_unknown(receiver_type)) {
3816 ctx->this_type = receiver_type;
3817 }
3818 TSNode params = kt_child_kind(lambda, "lambda_parameters");
3819 if (ts_node_is_null(params)) {
3820 if (receiver_type && !cbm_type_is_unknown(receiver_type)) {
3821 ctx->it_type = receiver_type;
3822 }
3823 } else {
3824 uint32_t pnc = ts_node_named_child_count(params);
3825 for (uint32_t i = 0; i < pnc; i++) {
3826 TSNode pn = ts_node_named_child(params, i);
3827 TSNode id = kt_name_child(pn);
3828 if (ts_node_is_null(id)) {
3829 id = kt_child_kind_named(pn, "simple_identifier");
3830 }
3831 if (!ts_node_is_null(id)) {
3832 char *name = kt_node_text(ctx, id);
3833 if (name) {
3834 /* Type annotation? */
3835 TSNode tn = kt_child_kind(pn, "type");
3836 const CBMType *t =
3837 ts_node_is_null(tn) ? cbm_type_unknown() : kotlin_parse_type_node(ctx, tn);
3838 cbm_scope_bind(ctx->current_scope, cbm_arena_strdup(ctx->arena, name), t);
3839 }
3840 }
3841 }
3842 }
3843 /* Walk lambda body */
3844 uint32_t nc = ts_node_named_child_count(lambda);
3845 for (uint32_t i = 0; i < nc; i++) {
3846 TSNode c = ts_node_named_child(lambda, i);
3847 const char *k = ts_node_type(c);
3848 if (strcmp(k, "lambda_parameters") == 0) {
3849 continue;
3850 }
3851 kt_process_statement(ctx, c);
3852 }
3853 ctx->it_type = prev_it;
3854 ctx->this_type = prev_this;
3855 ctx->current_scope = cbm_scope_pop(ctx->current_scope);
3856}
3857
3858static void kt_process_call_with_lambda(KotlinLSPContext *ctx, TSNode call_node) {
3859 /* If call has trailing lambda, propagate the receiver type as `it`.

Callers 1

Calls 12

cbm_scope_pushFunction · 0.85
cbm_type_is_unknownFunction · 0.85
kt_child_kindFunction · 0.85
kt_name_childFunction · 0.85
kt_child_kind_namedFunction · 0.85
kt_node_textFunction · 0.85
cbm_type_unknownFunction · 0.85
kotlin_parse_type_nodeFunction · 0.85
cbm_scope_bindFunction · 0.85
kt_process_statementFunction · 0.85
cbm_scope_popFunction · 0.85
cbm_arena_strdupFunction · 0.50

Tested by

no test coverage detected