| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Lua's M.foo = function(...) end module-table idiom and local f = function() end assign an anonymous function_definition node via a plain assignment_statement, which neither engine's extractor turned into a Definition, nor did the complexity function-node lists recognize function_definition as a function scope. Both silently got zero complexity/Halstead data. Add Definition-creation for identifier/dotted anonymous-function assignments in both extractors (mirroring the named function_declaration path), and add function_definition to LUA_RULES.function_nodes / complexityLua.functionNodes so nested anonymous functions get correct scope and nesting attribution in both engines. Closes #2036 Impact: 2 functions changed, 3 affected
Greptile SummaryThe PR adds Lua Definition extraction and complexity scoping for anonymous function-expression assignments in both native and WASM engines.
Confidence Score: 4/5The PR is not yet safe to merge because same-line anonymous-function assignments can still persist another function's complexity, Halstead, and CFG metrics. The new WASM Definitions use the RHS start line, while analysis results are grouped by that line and unnamed same-line function expressions fall back to the first candidate, so the previously reported incorrect metric attribution remains reachable. Files Needing Attention: src/extractors/lua.ts and src/ast-analysis/apply-results.ts Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart LR
Lua["Lua assignment"] --> Parse["Parse function_definition"]
Parse --> Extract["Create named Definition from LHS"]
Parse --> Analyze["Analyze RHS complexity and CFG"]
Extract --> Merge["Merge analysis onto Definition"]
Analyze --> Merge
Merge --> Persist["Persist graph metrics"]
Reviews (2): Last reviewed commit: "fix(lua): track complexity for anonymous..." | Re-trigger Greptile |
Sorry, something went wrong.
| ctx.definitions.push({ | ||
| name, | ||
| kind, | ||
| line: nodeStartLine(rhs), |
There was a problem hiding this comment.
When multiple assigned anonymous functions begin on the same line, both Definitions use that line while their anonymous analysis nodes provide no assignment name for disambiguation, so result matching selects the first candidate for each Definition and persists duplicated complexity, Halstead, and CFG metrics instead of each function's own results.
Knowledge Base Used: AST Extraction
Sorry, something went wrong.
|
Confirmed and investigated — this is a real gap, but it's pre-existing shared infrastructure, not something this PR introduces. matchResultToDef in src/ast-analysis/apply-results.ts disambiguates same-line candidates via funcNode.childForFieldName('name'), which is always null for any anonymous function node (JS arrow/function expressions included), falling back to candidates[0]. I reproduced the identical failure mode with plain JS, no Lua involved: const a = (x) => {
if (x) { return 1; }
return 0;
}, b = (x) => {
return 2;
};b's Definition gets a's complexity (cyclomatic 2/cognitive 1 instead of the correct 1/0) today, on main, unrelated to this PR — handleVarFnAssignment sets Definition.line from the enclosing statement, not each arrow function's own line, so b's line (1) collides with a's real result. Filed #2265 with the repro and a suggested column-aware fix, scoped as its own PR since it touches the shared matching path used by every language (not just Lua) and deserves focused review rather than scope-creeping this fix. This PR's own scope — the issue's exact repro (M.foo and f on separate lines) — is unaffected and verified with identical dual-engine numbers. |
Sorry, something went wrong.
Codegraph Impact Analysis2 functions changed → 5 callers affected across 3 files
|
Sorry, something went wrong.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Verification
Built the issue's own repro (local M = {}; M.foo = function(x) if x then return 1 else return 2 end end + local f = function(x) return x + 1 end) through the full buildGraph pipeline with both engines. Both now produce identical, real complexity:
Closes #2036
Test plan