Skip to content

feat: add proper ENUM, INTERFACE, TYPE, UNION node labels for Rust #260

@vitali87

Description

@vitali87

Problem

Rust enums, traits, type aliases, and unions are all being stored as CLASS nodes instead of their proper node labels (ENUM, INTERFACE, TYPE, UNION).

Root Cause

The determine_node_type function in codebase_rag/parsers/class_ingest/node_type.py has a match statement that handles TypeScript and C++ node types, but Rust-specific tree-sitter node types are missing.

Current behavior

All Rust types fall to the default case and become CLASS:

Rust Construct Tree-sitter Node Type Current Label Expected Label
enum Foo {} enum_item CLASS ENUM
trait Foo {} trait_item CLASS INTERFACE
type Foo = Bar type_item CLASS TYPE
union Foo {} union_item CLASS UNION
struct Foo {} struct_item CLASS CLASS

Technical Details

Tree-sitter-rust does provide distinct node types (verified in tree-sitter-rust grammar):

  • enum_item - with body: enum_variant_list, name: type_identifier
  • trait_item - with body: declaration_list, name: type_identifier
  • type_item - with name: type_identifier, type: _type
  • union_item - with body: field_declaration_list, name: type_identifier

The fix requires adding these cases to determine_node_type():

case cs.TS_RS_ENUM_ITEM:
    return NodeType.ENUM
case cs.TS_RS_TRAIT_ITEM:
    return NodeType.INTERFACE
case cs.TS_RS_TYPE_ITEM:
    return NodeType.TYPE
case cs.TS_RS_UNION_ITEM:
    return NodeType.UNION

Files to Modify

  • codebase_rag/parsers/class_ingest/node_type.py - Add Rust cases to determine_node_type()
  • codebase_rag/logs.py - Add log messages for Rust-specific types (e.g., CLASS_FOUND_TRAIT)
  • codebase_rag/tests/integration/test_node_label_e2e.py - Add tests for Rust ENUM, INTERFACE, TYPE, UNION

Impact

This enhancement would provide more accurate knowledge graph representation for Rust codebases, enabling better queries like "find all traits" or "find all enums in the project".

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working correctlyenhancementNew feature or requestrustRust language

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions