feat(cpp): improve C++ parser for inheritance, methods, and calls#734
Open
jannahopp wants to merge 1 commit intoCodeGraphContext:mainfrom
Open
feat(cpp): improve C++ parser for inheritance, methods, and calls#734jannahopp wants to merge 1 commit intoCodeGraphContext:mainfrom
jannahopp wants to merge 1 commit intoCodeGraphContext:mainfrom
Conversation
Major improvements to the C++ tree-sitter parser that enable proper graph construction for C++ codebases: 1. Inheritance extraction: Replace hardcoded bases placeholder with _extract_base_classes() that walks base_class_clause children. 2. Qualified method definitions: Add qualified_identifier to the functions query so Class::method() definitions are captured. 3. Scoped and arrow call patterns: Capture Class::staticMethod(), ptr->method(), and this->method() with inferred_obj_type. 4. Fix _get_parent_context: Use class_specifier instead of class_definition (Python node type vs C++ node type). 5. Deduplicate pre_scan_cpp paths to fix inheritance resolution. 6. Fix _find_lambda_assignments indentation bug. Note: call args field is now [] - the old code incorrectly extracted the function definitions params, not the call arguments. Depends on: fix/cpp-find-enums-nameerror Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@jannahopp is attempting to deploy a commit to the shashankss1205's projects Team on Vercel. A member of the Team first needs to authorize it. |
This was referenced Mar 17, 2026
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.
Summary
Major improvements to the C++ tree-sitter parser that enable proper graph construction for C++ codebases. On a real 300-file C++ project, these changes increased CALLS edges from 1,287 to 13,042 (10x) and INHERITS edges from 0 to 79.
Changes
1. Inheritance extraction
Replace hardcoded
"bases": []placeholder with_extract_base_classes()that walksbase_class_clausechildren. Handles public/private/protected/virtual inheritance, multiple inheritance, qualified base names (ns::Base), and template base classes (strips template args for graph matching).2. Qualified method definitions
Add
qualified_identifierto the functions tree-sitter query soClassName::method()definitions in .cpp files are captured with correctclass_context. Previously only free functions and simple identifiers matched, missing most C++ method bodies.3. Scoped and arrow call patterns
Add
qualified_identifierandfield_expressionhandling to the calls query. Now capturesClass::staticMethod(),ptr->method(), andthis->method()with properinferred_obj_typefor cross-file resolution.4. Fix _get_parent_context for C++
Use
class_specifier(the correct C++ tree-sitter node type) instead ofclass_definition(Python's type). Also handlequalified_identifierandfield_identifierwhen traversing function declarators.5. Deduplicate pre_scan_cpp paths
Prevent duplicate entries in the imports map that caused the inheritance resolver's
len(paths) == 1check to fail for classes with multiple qualified method definitions.6. Fix _find_lambda_assignments indentation
Correct a pre-existing indentation bug where the lambda type check ran outside the
capture_name == 'name'block, plus update staleclass_definitionreference.Note on args field
The
argsfield on call data is now[]instead of a list of parameter dicts. The old code was incorrectly extracting the function definition's parameters rather than the call's arguments.Tests
Added
tests/unit/parsers/test_cpp_parser.pywith 14 tests covering inheritance (5), qualified methods (2), call patterns (4), enums (2), and a realistic integration test (1).Depends on
🤖 Generated with Claude Code