fix(complexity): resolve real Julia/R function names in standalone analysis - #2566
Merged
Conversation
…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.
Contributor
Greptile SummaryThe PR makes native standalone complexity analysis resolve Julia and R function names using language-specific AST structures.
Confidence Score: 5/5The PR appears safe to merge because no blocking failure remains within the eligible follow-up review scope. No blocking failure remains. Important Files Changed
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 <anonymous>"]
Language -->|Other| Generic["Read direct name field"]
JuliaName --> Result["Standalone analysis result"]
RName --> Result
Anonymous --> Result
Generic --> Result
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
analyze_complexity_standalone/build_cfg_standalone's genericfunction_name()helper (crates/codegraph-core/src/ast_analysis/engine.rs) only checked a directnamefield on the function node, silently misreporting names for Julia and R — neither language'sfunction_definitionnode carries one."<anonymous>"— the name is nested undersignature→call_expression(seeextractors/julia.rs'ssignature_call, which the main extractor already uses correctly)."function", not merely"<anonymous>"as the issue assumed. Confirmed by direct AST inspection: tree-sitter-r's grammar does define anamefield onfunction_definition— it just points at thefunctionkeyword 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_callinextractors/julia.rsis nowpub(crate)and called directly.assigned_function_nameinextractors/r_lang.rs(mirroringhandle_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.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 ontoDefinitions 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_standaloneisn'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
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)"<anonymous>"for Julia, literal"function"for both R cases); restored and confirmed greentests/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.nodeaddon and ran the updated/new TS tests against it directly — 16/16 passedcargo test --lib(full suite) — 1101 passedcargo clippy --lib -- -D warnings— cleannpm test(full suite) — 339 files, 5454 passednpx tsc --noEmit/npm run lint— cleanCloses #2471