aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornotomo <notomo.motono@gmail.com>2025-01-25 21:15:01 +0900
committerChristian Clason <ch.clason+github@icloud.com>2025-01-29 09:15:13 +0100
commite7ebc5c13d2d1658005a7fb477bc92718044746f (patch)
tree5750bbce45d6f0ae69ae9d30a2bdc7ccada7247d
parent19f00bf32cebfa66a17e0f5945d62d7da1859623 (diff)
downloadrneovim-e7ebc5c13d2d1658005a7fb477bc92718044746f.tar.gz
rneovim-e7ebc5c13d2d1658005a7fb477bc92718044746f.tar.bz2
rneovim-e7ebc5c13d2d1658005a7fb477bc92718044746f.zip
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.
-rw-r--r--runtime/lua/vim/treesitter/languagetree.lua7
1 files changed, 6 insertions, 1 deletions
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua
index 5e1156fa68..8ea1c44cdc 100644
--- a/runtime/lua/vim/treesitter/languagetree.lua
+++ b/runtime/lua/vim/treesitter/languagetree.lua
@@ -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