Incremental reparse reuses a column-dependent token after its column changed
AI Policy
- I have read the AI Policy and this issue complies with it.
Problem
After an edit changes a token's column, an incremental reparse can reuse that token even though the external scanner called get_column for it. The result differs from a fresh parse.
Cause: ts_subtree_compress (called from ts_parser__balance_subtree) calls ts_subtree_summarize_children on rotated nodes whose size is stale. For i == 0, self.ptr->size.extent.row == 0 reads that stale size, so depends_on_column is not propagated from the first child.
Possible fix in lib/src/subtree.c:
- self.ptr->size.extent.row == 0 &&
+ (i == 0 || self.ptr->size.extent.row == 0) &&
ts_subtree_depends_on_column(child)Steps to reproduce
git clone --depth=1 https://github.com/exKAZUu/tree-sitter-depends-on-column-repro
cd tree-sitter-depends-on-column-repro
npm install
npm run reproThe scanner returns x as head at column 0 and as tail elsewhere. The script parses \nax\na, inserts \n before x, and reparses with --edits:
--- incremental
+++ fresh
- (tail [2, 0] - [2, 1])
+ (head [2, 0] - [2, 1])Expected behavior
The incremental reparse matches a fresh parse (head). With the fix above, it does.
Tree-sitter version (tree-sitter --version)
tree-sitter 0.27.0 (also reproduces with lib/ at master dcdc8cc5)
Operating system/version
macOS 27.0
Note: I used Claude Code with Opus 5.5 to find the cause and to write the reproduction repository and the draft of this issue. I checked the reproduction and the fix myself.
Source: tree-sitter/tree-sitter