feat(rust): add full parser support and resolution for Rust codebases#526
Open
gopinathnelluri wants to merge 2 commits into
Open
feat(rust): add full parser support and resolution for Rust codebases#526gopinathnelluri wants to merge 2 commits into
gopinathnelluri wants to merge 2 commits into
Conversation
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds full, comprehensive support for Rust codebases to
code-review-graph. Previously, Rust call graphs were sparse and disconnected due to missing type associations, unparsed traits, and lack of path/scoped call resolution.This implementation enables correct structural parsing of Rust features—including traits, inherent/trait
implblocks, relative/crate imports, and scoped calls—ensuring high-quality execution flow and impact radius analysis for Rust projects.Key Changes
1. AST Parsing & Extraction (
code_review_graph/parser.py)trait_itemunder Rust class types, allowing trait definitions to be parsed asClassnodes.implBlock Scope Association:implblocks are now mapped to their target struct/enum scope (stripping generics) rather than the trait name.implblocks are qualified under the implementing struct (e.g.,InMemoryRepo.save), matching how they are concrete-ly invoked.INHERITSEdges): Added Rust support to_get_basesto emit anINHERITSedge between the implementing struct and the trait inimpl Trait for Structblocks._parse_rust_use_node) for complex Rustusestatements (e.g.use a::{b, c::d}) and alias patterns (as).2. Scoped Path & Module Resolvers (
code_review_graph/parser.py)_do_resolve_module. It scans forCargo.tomlto identify the crate root, handlescrate::andself::segments, resolves nestedsuper::references, and maps them to absolute.rsormod.rsfiles._resolve_rust_scoped_calland integrated it in_resolve_call_target. It translates double-colon scoped calls (e.g.InMemoryRepo::new()) to dot-separated qualified method targets (e.g.,InMemoryRepo.new), bridging the AST call-site to the graph method node.Verification & Testing
Automated Tests
Extended the test suite in
tests/test_multilang.pywith:INHERITSconformance tracking.InMemoryRepo::new->InMemoryRepo.new).crate::andsuper::resolution.All 307 multilang tests pass successfully:
$ uv run pytest tests/test_multilang.py collected 307 items ======================== 307 passed, 1 warning in 6.02s ========================