fix(files): handle stale treesitter nodes gracefully#1076
Open
seflue wants to merge 1 commit intonvim-orgmode:masterfrom
Open
fix(files): handle stale treesitter nodes gracefully#1076seflue wants to merge 1 commit intonvim-orgmode:masterfrom
seflue wants to merge 1 commit intonvim-orgmode:masterfrom
Conversation
Member
kristijanhusak
left a comment
There was a problem hiding this comment.
Thanks for the PR! It seems unfinished though.
8c61052 to
5a46807
Compare
5a46807 to
e7dd352
Compare
| -- Track changedtick for staleness detection | ||
| local bufnr = self:bufnr() | ||
| if bufnr > -1 then | ||
| self._parse_tick = vim.api.nvim_buf_get_changedtick(bufnr) |
Member
|
Do you know how can I reproduce this? Cache should revalidate when node changes, and I'm curious if we could handle it differently. |
When a buffer changes after parsing, node positions become invalid. Calling get_node_text on stale nodes throws "Index out of bounds" errors, crashing async callers like org-roam. Changes: - Wrap get_node_text in pcall, return '' on failure - Add is_tree_stale() for callers needing explicit detection - Track buffer changedtick at parse time for comparison
e7dd352 to
7e9471b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes intermittent "Index out of bounds" errors when treesitter nodes become stale after buffer modifications.
The error occurs when:
vim.schedule)Example error:
Related Issues
Changes
get_node_text()inpcallto gracefully handle stale nodes_parse_tickfield to track buffer state at parse timeOrgFile:is_tree_stale()for callers that need explicit staleness checksChecklist
I confirm that I have:
feat: add new feature,fix: correct bug,docs: update documentation).make test.