Handle Elixir def/defp/defmacro — extract function definition.
| 8775 | |
| 8776 | // Handle Elixir def/defp/defmacro — extract function definition. |
| 8777 | static void extract_elixir_func_def(CBMExtractCtx *ctx, TSNode node, const char *macro) { |
| 8778 | CBMArena *a = ctx->arena; |
| 8779 | TSNode args = elixir_call_args(node); |
| 8780 | if (ts_node_is_null(args)) { |
| 8781 | return; |
| 8782 | } |
| 8783 | |
| 8784 | TSNode first_arg = ts_node_child(args, 0); |
| 8785 | if (ts_node_is_null(first_arg)) { |
| 8786 | return; |
| 8787 | } |
| 8788 | |
| 8789 | const char *fk = ts_node_type(first_arg); |
| 8790 | char *name = NULL; |
| 8791 | if (strcmp(fk, "call") == 0 && ts_node_child_count(first_arg) > 0) { |
| 8792 | name = cbm_node_text(a, ts_node_child(first_arg, 0), ctx->source); |
| 8793 | } else if (strcmp(fk, "identifier") == 0) { |
| 8794 | name = cbm_node_text(a, first_arg, ctx->source); |
| 8795 | } |
| 8796 | if (!name || !name[0]) { |
| 8797 | return; |
| 8798 | } |
| 8799 | |
| 8800 | CBMDefinition def; |
| 8801 | memset(&def, 0, sizeof(def)); |
| 8802 | def.name = name; |
| 8803 | def.qualified_name = cbm_fqn_compute(a, ctx->project, ctx->rel_path, name); |
| 8804 | def.label = "Function"; |
| 8805 | def.file_path = ctx->rel_path; |
| 8806 | def.start_line = ts_node_start_point(node).row + TS_LINE_OFFSET; |
| 8807 | def.end_line = ts_node_end_point(node).row + TS_LINE_OFFSET; |
| 8808 | def.is_exported = (strcmp(macro, "def") == 0 || strcmp(macro, "defmacro") == 0); |
| 8809 | cbm_defs_push(&ctx->result->defs, a, def); |
| 8810 | } |
| 8811 | |
| 8812 | // Emit Class definition for an Elixir defmodule node. Returns do_block or null. |
| 8813 | static TSNode emit_elixir_module_class(CBMExtractCtx *ctx, TSNode cur) { |
no test coverage detected