Merge pull request #2169 from TyceHerrman/fix/treesitter-buffer-validity
Check Lua Formatting / Stylua Check (push) Canceled after 0s

Check buffer validity before loading Treesitter parser
This commit is contained in:
Ori Perry
2026-10-03 14:54:01 +03:00
committed by GitHub
+3 -3
View File
@@ -954,12 +954,12 @@ do
---@param buf integer ---@param buf integer
---@param language string ---@param language string
local function treesitter_try_attach(buf, language) local function treesitter_try_attach(buf, language)
-- Check if a parser exists and load it
if not vim.treesitter.language.add(language) then return end
-- Check if the buffer is valid (might not be after install completes) -- Check if the buffer is valid (might not be after install completes)
if not vim.api.nvim_buf_is_valid(buf) then return end if not vim.api.nvim_buf_is_valid(buf) then return end
-- Check if a parser exists and load it
if not vim.treesitter.language.add(language) then return end
-- Enable syntax highlighting and other treesitter features -- Enable syntax highlighting and other treesitter features
vim.treesitter.start(buf, language) vim.treesitter.start(buf, language)