Skip to content

Feature request: Distinguish read vs write references for variables (lvalue/rvalue) #996

Description

@FrankSnipes1983

Problem

Currently, the references edge type doesn't distinguish whether a variable is being read (rvalue) or written (lvalue). For example, both x = 1 and y = x generate the same references edge, making it impossible to answer questions like "where is this global variable being modified?"

Proposed Solution

Split references into reads and writes edge types based on the variable's position in the AST:

  • writes: variable appears on the left side of an assignment (lvalue)
  • reads: variable appears on the right side or in expressions (rvalue)

Tree-sitter already provides this information — assignment nodes have left and right child nodes in most language grammars.

Use Case

When analyzing global variables or shared state, it's critical to know where a variable is written vs read. This is especially useful for debugging, refactoring, and impact analysis.

Implementation Notes

Different languages have different assignment node types in tree-sitter:

  • Python: assignment with left/right
  • JS/TS: assignment_expression, variable_declarator
  • C/C++: assignment_expression, init_declarator
  • Go: assignment_statement, short_var_declaration
  • Rust: let_declaration, assignment_expression

For compound assignments (+=, -=, etc.), the variable is both read and written — could be represented as both reads and writes edges, or a new read_write edge type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions