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.
Problem
Currently, the
referencesedge type doesn't distinguish whether a variable is being read (rvalue) or written (lvalue). For example, bothx = 1andy = xgenerate the samereferencesedge, making it impossible to answer questions like "where is this global variable being modified?"Proposed Solution
Split
referencesintoreadsandwritesedge 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
leftandrightchild 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:
assignmentwithleft/rightassignment_expression,variable_declaratorassignment_expression,init_declaratorassignment_statement,short_var_declarationlet_declaration,assignment_expressionFor compound assignments (
+=,-=, etc.), the variable is both read and written — could be represented as bothreadsandwritesedges, or a newread_writeedge type.