From db7660aaf05662a007e41b9eb365de9741e133bb Mon Sep 17 00:00:00 2001 From: Martin Vogel Date: Fri, 26 Jun 2026 22:08:02 +0200 Subject: [PATCH] fix(extract): enclosing-func detection uses lang_spec function_node_types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause of the systemic callable-sourcing gap (QUALITY_ANALYSIS gap #3; only 3.69% of real-repo CALLS were Function/Method-sourced): func_kinds_for_lang fell back to func_kinds_generic for the ~130 languages without a curated entry, missing their real function node types, so cbm_find_enclosing_func never found the parent function and attributed in-body calls to the Module node. Fix: in the default case, use the language spec's function_node_types (the single source of truth extraction already uses) when present. Curated languages (Go/ Python/C/C++/Rust/Java/...) are unchanged — no regression to the green gate. Flips the callable-sourcing + enclosing-parity reproductions for the drifted languages (dart/perl/scss/nix/fortran/cobol/verilog/vhdl/...) toward green. Signed-off-by: Martin Vogel --- internal/cbm/helpers.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/cbm/helpers.c b/internal/cbm/helpers.c index c34be9b7c..7a36aa756 100644 --- a/internal/cbm/helpers.c +++ b/internal/cbm/helpers.c @@ -692,9 +692,24 @@ static const char **func_kinds_for_lang(CBMLanguage lang) { return func_kinds_magma; case CBM_LANG_WOLFRAM: return func_kinds_wolfram; - default: + default: { + /* Enclosing-function drift fix (QUALITY_ANALYSIS gap #3): languages + * without a curated func_kinds entry previously fell back to + * func_kinds_generic, which misses their real function node types + * (e.g. dart function_signature, perl subroutine_declaration_statement, + * scss mixin_statement, nix function_expression, fortran subroutine, + * cobol program_definition, verilog/vhdl, ...). The enclosing-function + * walk then never found the parent function and attributed every + * in-body call to the Module node. Use the language spec's + * function_node_types (the single source of truth that extraction + * already uses) when the curated switch has no entry. Curated languages + * above are unchanged. */ + const CBMLangSpec *spec = cbm_lang_spec(lang); + if (spec && spec->function_node_types && spec->function_node_types[0]) + return spec->function_node_types; return func_kinds_generic; } + } } TSNode cbm_find_enclosing_func(TSNode node, CBMLanguage lang) {