Skip to content

fix(complexity): resolve real Julia/R function names in standalone analysis - #2566

Merged
carlos-alm merged 2 commits into
mainfrom
fix/issue-2471
Aug 18, 2026
Merged

fix(complexity): resolve real Julia/R function names in standalone analysis#2566
carlos-alm merged 2 commits into
mainfrom
fix/issue-2471

Conversation

@carlos-alm

Copy link
Copy Markdown
Contributor

Summary

analyze_complexity_standalone/build_cfg_standalone's generic function_name() helper (crates/codegraph-core/src/ast_analysis/engine.rs) only checked a direct name field on the function node, silently misreporting names for Julia and R — neither language's function_definition node carries one.

  • Julia: reported "<anonymous>" — the name is nested under signaturecall_expression (see extractors/julia.rs's signature_call, which the main extractor already uses correctly).
  • R: reported the literal string "function", not merely "<anonymous>" as the issue assumed. Confirmed by direct AST inspection: tree-sitter-r's grammar does define a name field on function_definition — it just points at the function keyword token itself, not an identifier (R has no named-function-definition syntax at all; every function acquires a name only via assignment, e.g. greet <- function(name) {...}). This makes the pre-fix bug actively worse than the issue described, not just a missing name.

Fix

Reuses each language's own already-correct extractor logic rather than re-deriving it:

  • signature_call in extractors/julia.rs is now pub(crate) and called directly.
  • A new assigned_function_name in extractors/r_lang.rs (mirroring handle_binary_op's operator/identifier validation, in the opposite bottom-up direction — given the function node, walk up to its parent) resolves R's enclosing-assignment name.
  • R is never allowed to fall through to the generic child_by_field_name("name") lookup at all (for either the named or anonymous case), since that lookup is actively wrong for R's grammar.

Rust-only change — the JS-side native-standalone-analysis fallback (src/ast-analysis/engine.ts) already matches results back onto Definitions primarily by line number (per the issue's own note), so it wasn't visibly affected and needs no TS-side fix.

Scope note

build_cfg_standalone isn't actually affected in practice for either language: get_cfg_rules (ast_analysis/cfg.rs) has no entry for Julia or R at all yet, so it already returns zero results for both regardless of this fix — a separate, pre-existing, out-of-scope gap (CFG support hasn't been built for these languages), not something this name-resolution fix touches.

Also fixes an existing test from #2312 that had documented this exact bug's symptom as an accepted, out-of-scope gap in a comment rather than tracking it as a real bug to fix — per this repo's own CLAUDE.md, that pattern is exactly what issue #2471 was filed to close out.

Test plan

  • New Rust tests in ast_analysis/engine.rs: Julia named function resolves correctly, R named function resolves correctly, R anonymous inline function reports "<anonymous>" (not the misleading "function" keyword)
  • Revert-verified: temporarily restored the original generic-fallback-only behavior and confirmed all three new tests fail with the exact pre-fix symptoms ("<anonymous>" for Julia, literal "function" for both R cases); restored and confirmed green
  • Updated tests/unit/native-analysis.test.ts's existing Julia test to assert the real name instead of documenting the bug as expected; added a new end-to-end R test through the real NAPI surface
  • Rebuilt the native .node addon and ran the updated/new TS tests against it directly — 16/16 passed
  • cargo test --lib (full suite) — 1101 passed
  • cargo clippy --lib -- -D warnings — clean
  • npm test (full suite) — 339 files, 5454 passed
  • npx tsc --noEmit / npm run lint — clean

Closes #2471

…alysis

analyze_complexity_standalone / build_cfg_standalone's generic function_name()
helper only checked a direct `name` field, silently misreporting names for
Julia and R -- neither language's function_definition node carries one.

Julia: reported "<anonymous>" -- the name is nested under signature ->
call_expression (extractors/julia.rs's signature_call, which the main
extractor already used correctly).

R: reported the literal string "function", not merely "<anonymous>" as the
issue assumed -- confirmed by direct AST inspection that tree-sitter-r's
grammar DOES define a `name` field on function_definition, but it points at
the "function" keyword token itself, not an identifier (R has no
named-function-definition syntax; every function acquires a name only via
assignment, e.g. `greet <- function(name) {...}`).

Reuses each language's own already-correct extractor logic instead of
re-deriving it: signature_call is now pub(crate) and called directly for
Julia; a new assigned_function_name in r_lang.rs (mirroring
handle_binary_op's operator/identifier validation, in the opposite
top-down/bottom-up direction) resolves R's enclosing-assignment name. R is
never allowed to fall through to the generic name lookup, since that lookup
is actively wrong for R's grammar regardless of whether the function is
named or anonymous.

Rust-only change: the JS-side native-standalone-analysis fallback
(src/ast-analysis/engine.ts) already matches results back onto Definitions
primarily by line number, so it was not visibly affected by this bug and
needs no corresponding TS-side fix.

Also updates an existing #2312 test that had documented this exact bug's
symptom as an accepted, out-of-scope gap rather than fixing it, and adds a
new R end-to-end test through the real NAPI surface.

docs check acknowledged -- bug fix only, no new language support, feature,
or architectural change to document.
@greptile-apps

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR makes native standalone complexity analysis resolve Julia and R function names using language-specific AST structures.

  • Reuses Julia signature discovery for standalone result names.
  • Resolves R function names from enclosing assignments while preserving anonymous inline functions.
  • Adds Rust and native-addon regression coverage for Julia and R.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains within the eligible follow-up review scope.

No blocking failure remains.

Important Files Changed

Filename Overview
crates/codegraph-core/src/ast_analysis/engine.rs Dispatches standalone function-name extraction to Julia- and R-specific helpers and adds focused regression tests.
crates/codegraph-core/src/extractors/julia.rs Exposes the existing signature-call helper within the crate for reuse by standalone analysis.
crates/codegraph-core/src/extractors/r_lang.rs Adds bottom-up resolution for directly assigned R function definitions.
tests/unit/native-analysis.test.ts Updates native integration coverage to require real Julia and R function names.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  AST["Function AST node"] --> Language{"Language"}
  Language -->|Julia| Signature["Find signature call"]
  Signature --> JuliaName["Read signature callee"]
  Language -->|R| Assignment["Inspect enclosing assignment"]
  Assignment -->|Named assignment| RName["Use left-hand identifier"]
  Assignment -->|Inline function| Anonymous["Return &lt;anonymous&gt;"]
  Language -->|Other| Generic["Read direct name field"]
  JuliaName --> Result["Standalone analysis result"]
  RName --> Result
  Anonymous --> Result
  Generic --> Result
Loading

Reviews (2): Last reviewed commit: "style(rust): apply cargo fmt to assigned..." | Re-trigger Greptile

CI's "Rust compile check" job runs cargo fmt -- --check, which the
previous commit missed running locally before pushing.
@carlos-alm
carlos-alm merged commit 5f51202 into main Aug 18, 2026
46 of 48 checks passed
@carlos-alm
carlos-alm deleted the fix/issue-2471 branch August 18, 2026 10:59
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

analyze_complexity_standalone / build_cfg_standalone report "<anonymous>" for Julia (and R) functions

1 participant