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

Function kt_process_lambda

internal/cbm/lsp/kotlin_lsp.c:3807–3861  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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