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 authored and Christian Clason committed 2025-01-29 09:15:13 +01:00
1 parent 19f00bf32c
commit e7ebc5c13d
1 file changed
+6 -1
+6 -1
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