Handle Elixir def/defp/defmacro — extract function definition.
| 4986 | |
| 4987 | // Handle Elixir def/defp/defmacro — extract function definition. |
| 4988 | static void extract_elixir_func_def(CBMExtractCtx *ctx, TSNode node, const char *macro) { |
| 4989 | CBMArena *a = ctx->arena; |
| 4990 | TSNode args = elixir_call_args(node); |
| 4991 | if (ts_node_is_null(args)) { |
| 4992 | return; |
| 4993 | } |
| 4994 | |
| 4995 | TSNode first_arg = ts_node_child(args, 0); |
| 4996 | if (ts_node_is_null(first_arg)) { |
| 4997 | return; |
| 4998 | } |
| 4999 | |
| 5000 | const char *fk = ts_node_type(first_arg); |
| 5001 | char *name = NULL; |
| 5002 | if (strcmp(fk, "call") == 0 && ts_node_child_count(first_arg) > 0) { |
| 5003 | name = cbm_node_text(a, ts_node_child(first_arg, 0), ctx->source); |
| 5004 | } else if (strcmp(fk, "identifier") == 0) { |
| 5005 | name = cbm_node_text(a, first_arg, ctx->source); |
| 5006 | } |
| 5007 | if (!name || !name[0]) { |
| 5008 | return; |
| 5009 | } |
| 5010 | |
| 5011 | CBMDefinition def; |
| 5012 | memset(&def, 0, sizeof(def)); |
| 5013 | def.name = name; |
| 5014 | def.qualified_name = cbm_fqn_compute(a, ctx->project, ctx->rel_path, name); |
| 5015 | def.label = "Function"; |
| 5016 | def.file_path = ctx->rel_path; |
| 5017 | def.start_line = ts_node_start_point(node).row + TS_LINE_OFFSET; |
| 5018 | def.end_line = ts_node_end_point(node).row + TS_LINE_OFFSET; |
| 5019 | def.is_exported = (strcmp(macro, "def") == 0 || strcmp(macro, "defmacro") == 0); |
| 5020 | cbm_defs_push(&ctx->result->defs, a, def); |
| 5021 | } |
| 5022 | |
| 5023 | // Emit Class definition for an Elixir defmodule node. Returns do_block or null. |
| 5024 | static TSNode emit_elixir_module_class(CBMExtractCtx *ctx, TSNode cur) { |
no test coverage detected