Repository navigation
Description
Summary
codegraph complexity --file <f> --health -T --json silently returns functions: [] for any file in a language outside a small supported subset — not because those files lack functions (codegraph where --file extracts them correctly), but because COMPLEXITY_RULES/HALSTEAD_RULES (src/ast-analysis/rules/index.ts) and the native mirror (lang_rules/halstead_rules in crates/codegraph-core/src/ast_analysis/complexity.rs) simply have no entry for the language. This is the same root-cause shape as #1782 (Lua), just unfixed for the remaining languages.
Confirmed via direct repro (native engine) for a spot-check of 4 languages, all returning functions: 0 despite the fixtures having real functions:
$ codegraph complexity --file tests/benchmarks/resolution/fixtures/elixir/main.ex --health -T --json --engine native
functions: 0
$ codegraph complexity --file tests/benchmarks/resolution/fixtures/zig/main.zig --health -T --json --engine native
functions: 0
$ codegraph complexity --file tests/benchmarks/resolution/fixtures/gleam/main.gleam --health -T --json --engine native
functions: 0
$ codegraph complexity --file tests/benchmarks/resolution/fixtures/clojure/main.clj --health -T --json --engine native
functions: 0
Exact scope (post-#1782, i.e. after Lua is fixed)
LANGUAGE_REGISTRY has 36 entries (35 real languages + intentionally-excluded hcl, which has no function/branch concept and should stay excluded).
TS COMPLEXITY_RULES/HALSTEAD_RULES supported (11): javascript, typescript, tsx, python, go, rust, java, csharp, ruby, php, lua
TS missing (24): c, cpp, kotlin, swift, scala, bash, elixir, dart, zig, haskell, ocaml, ocaml-interface, fsharp, fsharp-signature, gleam, clojure, julia, r, erlang, solidity, objc, cuda, groovy, verilog
Native Rust lang_rules/halstead_rules supported (16, post-#1782): javascript, typescript, tsx, python, go, rust, java, csharp, ruby, php, c, cpp, kotlin, swift, scala, bash, lua
Native missing (17): dart, zig, haskell, ocaml, ocaml-interface, fsharp, fsharp-signature, gleam, clojure, julia, r, erlang, solidity, objc, cuda, groovy, verilog
So there are two tiers of follow-up work:
- 6 languages (c, cpp, kotlin, swift, scala, bash) already have a native
LangRules/HalsteadRulesdefinition (defined incomplexity.rsbut never wired into the WASM/TS side) — porting these tosrc/ast-analysis/rules/*.tsshould be a comparatively mechanical translation of the existing Rust rule struct, plus wiring intoCOMPLEXITY_RULES/HALSTEAD_RULES. - 17 languages have no complexity model on either engine and need the same from-scratch grammar investigation codegraph complexity --file returns empty functions[] for Lua files #1782 required for Lua: confirming real tree-sitter node types for branch/loop/logical-operator/function constructs (do not assume node names transfer from a similar-looking language), figuring out the if/elseif/else structural pattern (flat siblings vs nested vs alternative-field), and — notably — several of these are functional/pattern-matching languages (Haskell, OCaml, F#, Clojure, Erlang, Gleam) whose control flow doesn't map cleanly onto the existing branch/nesting/cyclomatic model built around imperative if/for/while constructs. Those will need real design thought (e.g. what counts as a "branch" for a
case/pattern-match expression with N clauses, or for guards), not just a config port.
Suggested approach
Not a single PR — likely one PR per language or small batch, mirroring how dataflow rules were rolled out in batches (P5 Batch B1–B5, see src/ast-analysis/rules/b2.ts–b5.ts). Tier 1 (c/cpp/kotlin/swift/scala/bash) is lower-risk and could go first since the native rule shape already exists as a reference. Tier 2 languages should be tackled individually or in small groups given the design work needed for non-imperative control flow.
Scope note
Not fixed as part of #1782 — that issue was scoped specifically to Lua. Filing this as the tracking issue for the broader gap per repo scope-discipline convention (task instructions for #1782 explicitly called for filing a follow-up here rather than expanding that PR into a 24-language audit).
Activity
carlos-alm commentedon Jul 30, 2026
Progress update from a
/fixerpass on this issue:Tier 1 (c, cpp, kotlin, swift, scala, bash) is already fully done — confirmed on current
main: all six are wired into bothCOMPLEXITY_RULES/HALSTEAD_RULES(TS) andlang_rules()/halstead_rules()(native), matching this issue's own tier-1 description exactly.Attempted Dart next (first tier-2 language, chosen as the most mechanical/lowest-risk per this issue's suggested approach) — investigated tree-sitter-dart's grammar in depth (branch/loop/logical-operator/case node types, operator leaf shapes for Halstead,
if_statement'salternative-field else-if pattern) and had complexity/Halstead rules mirrored in both engines and passing my own hand-verified test cases, but discovered a blocking, pre-existing bug before landing it:function_signature/method_signaturenever contains the function's own body —function_bodyis an adjacent sibling, not a child, for both top-level functions and class methods. This breaks the shared engine's function-scope tracking (confirmed for both the standalone DFS reference and the visitor-based batch path used duringcodegraph build), not just something my new rules could work around. Filed as #2182 with full evidence and a suggested fix direction, since it's foundational (likely also affects the already-existingdataflowDartconfig, unverified) rather than specific to complexity.Reverted the Dart wiring rather than land rules that would silently produce wrong data (every function reporting the trivial base complexity regardless of actual branching) — landing "supported" but broken is worse than not supporting it yet.
Recommendation for whoever picks up Dart next: fix #2182 first, then the complexity/Halstead rules I derived (branch/case/logical-operator/optional-chain node types, Halstead operator/operand leaf sets) should be usable close to as-is — the grammar investigation is the expensive part and is now done, just not yet landed.
No change to the remaining 16 languages' status.
fix(complexity): add cognitive/cyclomatic/Halstead support for CUDA (#…
feat: add complexity metrics for Objective-C (#1923) (#2233)
carlos-alm commentedon Aug 3, 2026
Progress update from a follow-up
/fixerpass on this issue:Objective-C (tier 2) is now done — merged in #2233. tree-sitter-objc extends tree-sitter-c: if/else/for/while/switch/case/logical-operator/conditional-expression node kinds are byte-identical to plain C (confirmed by parsing sample ObjC control flow and inspecting the S-expression), including the same else_clause wrapper (Pattern A). Wired
COMPLEXITY_RULES/HALSTEAD_RULES(TS) andlang_rules()/halstead_rules()(native) forobjc, extending C's rule shape withmethod_definitionin functionNodes andcatch_clause(from@try/@catch/@finally) as a branch/nesting node — the same treatment C++'s catch_clause already gets.message_expression/selector_expressionare treated as compound Halstead operators, mirroringcall_expression.While verifying native/WASM parity for this, found and fixed a real divergence: the native ObjC extractor's
handle_methodran complexity/CFG analysis unconditionally on bothmethod_declaration(an@interface/@protocolsignature, which never has a body) andmethod_definition, producing a spurious trivial complexity entry that duplicated the real method entry under the same dotted name. Gated both on actual body presence and setbodylessaccordingly on both engines. Verified native and WASM now produce byte-identicalcodegraph complexity --health --jsonoutput on a hand-built fixture covering if/else-if/else, classic and fast-enumeration for loops, switch/case,@try/@catch/@finally, ternary, and message sends.No change to tier-1 (c/cpp/kotlin/swift/scala/bash) or CUDA — all already confirmed done on current
main.Remaining unattempted (16, minus Dart which is blocked on #2182 — do not attempt until that's fixed): zig, haskell, ocaml, ocaml-interface, fsharp, fsharp-signature, gleam, clojure, julia, r, erlang, solidity, groovy, verilog.
feat: add complexity metrics for Zig (#1923) (#2281)
fix: correct switch/case complexity shadowing and comment-prefix unde…
fix(skills): housekeep branch pruning ignores squash merges; fixer ne…
carlos-alm commentedon Aug 7, 2026
Progress update from a
/fixerpass on this issue:R and Groovy (tier 2) are now done — PR #2313. Both confirmed via direct grammar investigation rather than assumption: R's
if_statementcarriesconsequence/alternativefields directly (Pattern C, noelse_clausewrapper), has no switch statement (switch(x, ...)is an ordinary function call), and treatsrepeatas an unconditional loop (same as Rust'sloop). Groovy extends tree-sitter-java's grammar almost byte-for-byte;closureis deliberately excluded fromfunctionNodessince this grammar reuses it ambiguously for plain if/for/while/switch block bodies as well as real closures — including it would fabricate a spurious extra "function" per such body.Julia and Solidity turned out to need an engine enhancement, not a rules port — filed as #2312 rather than expanding this PR's scope. Julia wraps every operator (
+,>,&&, ...) in one genericoperatornode type, indistinguishable except by.text, which the currentclassifyLogicalOp/is_logical_opnode-type matching can't handle. Solidity wraps every statement/expression in a genericstatement/expressionnode, and both the "then" and "else-if"/"else" branches ofif_statementshare the same field namebody(noalternativefield, noelse_clausewrapper) — breaking both else-if detection patterns the engine currently supports.Remaining unattempted: dart (blocked on #2182), haskell, ocaml, ocaml-interface, fsharp, fsharp-signature, gleam, clojure, erlang (all flagged in #2312 as needing real design thought for pattern-match/guard "branch" semantics), verilog (no existing dataflow-rule investigation to build on, needs from-scratch grammar work), plus julia/solidity pending the #2312 engine fix.
feat(complexity): add R and Groovy complexity/Halstead rules (#1923) (#…
fix(ast-analysis): keep function scope active through Dart's sibling …