fix(treesitter): stop async parsing if buffer is invalid

Problem: Error occurs if delete buffer in the middle of parsing.
Solution: Check if buffer is valid in parsing.
This commit is contained in:
notomo
2025-01-25 21:15:01 +09:00
committed by Christian Clason
parent 19f00bf32c
commit e7ebc5c13d

View File

@@ -475,13 +475,18 @@ function LanguageTree:_async_parse(range, on_parse)
return
end
local buf = vim.b[self._source]
local source = self._source
local buf = vim.b[source]
local ct = buf.changedtick
local total_parse_time = 0
local redrawtime = vim.o.redrawtime
local timeout = not vim.g._ts_force_sync_parsing and default_parse_timeout_ms or nil
local function step()
if type(source) == 'number' and not vim.api.nvim_buf_is_valid(source) then
return nil
end
-- If buffer was changed in the middle of parsing, reset parse state
if buf.changedtick ~= ct then
ct = buf.changedtick