Skip to content

Check buffer validity before loading Treesitter parser - #2169

Merged
oriori1703 merged 1 commit into
nvim-lua:masterfrom
TyceHerrman:fix/treesitter-buffer-validity
Oct 3, 2026
Merged

oriori1703 merged 1 commit into
nvim-lua:masterfrom
TyceHerrman:fix/treesitter-buffer-validity

Conversation

@TyceHerrman

Copy link
Copy Markdown
Contributor

If a buffer is wiped before asynchronous parser installation finishes, the attachment callback receives an invalid buffer number. Check validity before loading the parser (i.e., calling vim.treesitter.language.add() ) so the attachment callback returns without loading a parser for an invalid buffer, avoiding unnecessary work.

This change moves the existing guard earlier. Valid buffer attachment behavior stays the same.

@oriori1703

oriori1703 commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

This seems to be the initial place for the check in bd5406e, but it was changed in the next commit (3711862) to be how it is now.

@ollien do you remember what was your reason for changing the order?

@ollien

ollien commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

@oriori1703 I don't think I had a reason grounded in evidence. I was mostly concerned with the install path, and it made sense to me to still load the parser. Thinking on it though, maybe this was misguided.

@oriori1703

Copy link
Copy Markdown
Collaborator

@oriori1703 I don't think I had a reason grounded in evidence. I was mostly concerned with the install path, and it made sense to me to still load the parser. Thinking on it though, maybe this was misguided.

sounds good enough for me to merge this :)

@oriori1703
oriori1703 merged commit 8e35dbe into nvim-lua:master Oct 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants