perf: forward langId hint to native standalone analysis functions#743
perf: forward langId hint to native standalone analysis functions#743carlos-alm merged 5 commits intomainfrom
Conversation
Pass the JS-resolved langId as an explicit Option<String> to the three native standalone analysis functions (analyzeComplexity, buildCfgAnalysis, extractDataflowAnalysis). Rust now uses the hint as the primary language, falling back to extension detection only when None. This ensures files whose language is inferred by content rather than extension (e.g. .vue files tagged as "javascript", extensionless shebang files) use the native Rust path instead of silently falling back to WASM. Closes #739
|
Claude finished @carlos-alm's task —— View job PR Review AnalysisReviewing PR #743: perf: forward langId hint to native standalone analysis functions Root Cause AnalysisProblem Being Solved: The native Rust standalone analysis functions ( Why This Approach: The JS engine already resolves Risk Assessment: Low risk. This is a pure optimization that maintains backward compatibility via fallback behavior. Backlog Compliance
Code Quality AssessmentRust Implementation (
|
Greptile SummaryThis PR threads a JS-resolved
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant E as engine.ts (runNativeAnalysis)
participant N as NativeAddon (napi-rs)
participant L as lib.rs (#[napi] wrapper)
participant A as analysis.rs (parse_source)
participant TS as tree-sitter
E->>E: resolve langId from JS engine<br/>(e.g. "javascript" for .vue)
E->>E: langSupports* = EXTENSIONS.has(ext) || RULES.has(langId)
alt needsComplexity
E->>N: analyzeComplexity(source, absPath, langId)
N->>L: analyze_complexity(source, file_path, Some("javascript"))
L->>A: parse_source(source, path, Some("javascript"))
A->>A: LanguageKind::from_lang_id("javascript") → Some(JS)
A->>TS: parse with JS grammar
TS-->>A: Tree
A-->>L: Some((Tree, JS))
L-->>N: Vec<FunctionComplexityResult>
N-->>E: results
end
alt lang_id is None (extension-only file)
E->>N: analyzeComplexity(source, absPath, langId)
N->>L: analyze_complexity(source, file_path, None)
L->>A: parse_source(source, path, None)
A->>A: from_lang_id(None) → None<br/>fallback: LanguageKind::from_extension(path)
A->>TS: parse with detected grammar
TS-->>A: Tree
A-->>L: Some((Tree, Lang))
L-->>N: Vec<FunctionComplexityResult>
N-->>E: results
end
Reviews (2): Last reviewed commit: "fix: use langId fallback in extension-se..." | Re-trigger Greptile |
| "peerDependencies": { | ||
| "tree-sitter": "^0.22.1" | ||
| }, | ||
| "peerDependenciesMeta": { | ||
| "tree-sitter": { | ||
| "optional": true | ||
| } | ||
| } | ||
| }, | ||
| "node_modules/tree-sitter-objc/node_modules/tree-sitter-c": { | ||
| "version": "0.23.6", | ||
| "resolved": "https://registry.npmjs.org/tree-sitter-c/-/tree-sitter-c-0.23.6.tgz", | ||
| "integrity": "sha512-0dxXKznVyUA0s6PjNolJNs2yF87O5aL538A/eR6njA5oqX3C3vH4vnx3QdOKwuUdpKEcFdHuiDpRKLLCA/tjvQ==", | ||
| "dev": true, | ||
| "hasInstallScript": true, | ||
| "license": "MIT", | ||
| "dependencies": { | ||
| "node-addon-api": "^8.3.0", | ||
| "node-gyp-build": "^4.8.4" | ||
| }, | ||
| "peerDependencies": { |
There was a problem hiding this comment.
yarn pulled in as a runtime dependency via tree-sitter-solidity
tree-sitter-solidity@1.2.13 declares yarn@^1.22.21 as a runtime (non-dev) dependency, which causes yarn@1.22.22 to be installed into node_modules. This is unusual for a grammar package and inflates install size noticeably (yarn is a full package manager). While it doesn't affect correctness today, it is worth confirming this is acceptable before shipping — a future version of tree-sitter-solidity that fixes this packaging quirk would allow the dependency to be dropped.
There was a problem hiding this comment.
Acknowledged — the tree-sitter-solidity pulling in yarn as a runtime dep is a known upstream packaging quirk. This is unrelated to the changes in this PR (it comes from the lockfile reflecting existing devDeps). Filed as a separate concern to track.
… files (#743) The needsComplexity/needsCfg/needsDataflow guards gated solely on file-extension sets, so content-inferred files (.vue tagged as "javascript", extensionless shebang files) could never reach the native or WASM analysis paths despite having a valid langId. Add langId-based fallback checks to all guard sites: the native analysis dispatcher, the WASM pre-parse check, the per-file CFG visitor setup, and the per-file dataflow visitor setup.
|
Addressed Greptile's P1 finding about extension-set guards blocking content-inferred files: Problem: The Fix (9a6d5e6): Added
This completes the PR's stated goal: content-inferred files now correctly reach both the native and WASM analysis paths. |
1 similar comment
|
Addressed Greptile's P1 finding about extension-set guards blocking content-inferred files: Problem: The Fix (9a6d5e6): Added
This completes the PR's stated goal: content-inferred files now correctly reach both the native and WASM analysis paths. |
Summary
langIdas an explicitOption<String>to the three native standalone analysis functions (analyzeComplexity,buildCfgAnalysis,extractDataflowAnalysis)None.vuetagged as"javascript", extensionless shebang files) now use the native Rust path instead of silently falling back to WASMChanges
crates/codegraph-core/src/analysis.rsparse_sourceacceptslang_id: Option<&str>, triesfrom_lang_idfirst thenfrom_extensioncrates/codegraph-core/src/lib.rs#[napi]wrappers acceptlang_id: Option<String>src/types.tsNativeAddonsignatures updated with optionallangIdparametersrc/ast-analysis/engine.tsrunNativeAnalysisforwards already-resolvedlangIdto all three native callsTest plan
tsc --noEmit).vuefiles withlangId: "javascript"(manual or future test)Closes #739