Skip to content

Bug: CPP tree-sitter -> .h files parsed with C grammar instead of C++ — classes and methods missing from graph #898

Closed

Description

@diwanmail

Bug

.h header files are dispatched to tree_sitter_c instead of tree_sitter_cpp. This silently drops all C++ constructs (classes, virtual methods, namespaces, templates) during
AST extraction.

Root Causes

  1. Dispatch table maps .h → extract_c instead of extract_cpp
  2. _CPP_CONFIG missing field_declaration in function_types — method declarations in class bodies (e.g. pure virtuals) are skipped
  3. _get_cpp_func_name doesn't handle field_identifier — method names inside class bodies use field_identifier, not identifier

Impact

~500-600 method nodes missing from the graph. Abstract interfaces appear as empty nodes with only a namespace entry.

Proposed Fix

  • Map .h → extract_cpp (tree_sitter_cpp is a superset of C, safe for mixed codebases)
  • Add field_declaration to _CPP_CONFIG.function_types with a guard to skip data members
  • Extend _get_cpp_func_name to recognize field_identifier and unwrapped function_declarator children

Activity

  1. safishamsi commented on May 16, 2026

    @safishamsi
    Member

    Fixed in v0.8.7.

    Three changes:

    • .h files remain on the C grammar (routing them to C++ broke Linux-kernel/POSIX-style headers that use class/new as identifiers); .hpp/.hxx/.hh already used C++
    • Fixed the field_declaration extraction branch — the previous child type filter (field_declarator) doesn't exist in tree-sitter-cpp's AST so the block was a no-op; now uses children_by_field_name("declarator") which correctly handles int x, y; (multiple declarators) and static const int MAX = 100; (init_declarator)
    • Extended _get_cpp_func_name to handle field_identifier, destructor_name, and operator_name node types
  2. added 2 commits that reference this issue on May 16, 2026
    500e4a7
    b82d5d1
  3. diwanmail commented on May 16, 2026

    @diwanmail
    Author

    Will this change fix c++ . Lh header files with virtual methods?

  4. added 2 commits that reference this issue on Aug 13, 2026
    14fa78d
    22da27d
  5. added 2 commits that reference this issue on Sep 10, 2026
    474c2fa
    5f4919d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions