Skip to content

fix(cpp): six parser bugs dropping or corrupting graph data-Issue:1538 - #1628

Open
VasudhaM04 wants to merge 2 commits into
CodeGraphContext:mainfrom
VasudhaM04:fix/cpp-parser-1538
Open

fix(cpp): six parser bugs dropping or corrupting graph data-Issue:1538#1628
VasudhaM04 wants to merge 2 commits into
CodeGraphContext:mainfrom
VasudhaM04:fix/cpp-parser-1538

Conversation

@VasudhaM04

Copy link
Copy Markdown

Summary

Fixes six independent bugs in the C++ tree-sitter parser that produce incorrect graph data or silently dropped code elements. Each is isolated to CppTreeSitterParser or CPP_QUERIES, so they're fixed independently with no shared surface.

Fixes #1538

Bugs fixed

All in src/codegraphcontext/tools/languages/cpp.py.

# Symptom Root cause Fix
1 #include "local.h" → name "local.h" with quotes _find_imports stripped only <> strip "<>, matching the C parser
2 int x = 5;type: None, always read type off init_declarator, which has no such field read from the enclosing declaration
3 int count; never captured at all variables query matched only init_declarator shapes added a bare-identifier declarator pattern
4 inline class methods had no class_context only ::-qualified names set it walk ancestors for class_specifier
5 #define SQUARE(x) ... missed entirely macros query matched only preproc_def added preproc_function_def alternative
6 macro end_line one past the real end end_point[0] + 1 double-counts the trailing newline use end_point[0] when end column is 0

Bug 4 previously meant the indexer's C++ post-pass could not create
Class-[:CONTAINS]->Function edges for inline methods. Bug 1 also brought C++
in line with the C parser, which already used .strip('"<>').

Notes on the implementation

Bug 2's fix is guarded on assignment_node.type == 'init_declarator'. A
field_declaration carries type on the node itself, so walking up
unconditionally returns None and regresses class fields — caught during
verification.

Bug 3 dedupes on (name, row) so declarations matching both the initialized
and plain patterns aren't emitted twice.

Bug 4 is gated on if not class_context, so :: splitting still takes
precedence and file-scope functions still get no context.

Testing

New: tests/unit/parsers/test_cpp_parser_fixes.py — 15 tests. Each bug gets a
test pinning the fixed behaviour plus preservation tests for the neighbouring
behaviour the fix must not disturb (system includes, field declarations,
qualified methods, file-scope functions, object-like macros, multi-line macros,
lambda assignments), and one integration test combining all six scenarios to
catch cross-interference.

…notes

Relocate the six-bug regression tests to tests/unit/parsers/ so they are picked up by test discovery and run in CI, per CONTRIBUTING.md. Use the shared temp_test_dir fixture instead of a local sys.path shim. Remove the cpp_parser_fix/ spec working notes, which were scratch material rather than project documentation.
@vercel

vercel Bot commented Aug 14, 2026

Copy link
Copy Markdown

@VasudhaM04 is attempting to deploy a commit to the shashankss1205's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog tasks

Development

Successfully merging this pull request may close these issues.

bug(indexer): parser audit roundup — context attribution, wrong Module names, missing declarations and duplicate call records across 12 languages

1 participant