From 3d96e2c9f1c81b5e2b613451f3761534aeccd4e3 Mon Sep 17 00:00:00 2001 From: Calvin Bochulak Date: Wed, 22 May 2024 16:58:47 -0600 Subject: [PATCH] fix: add pcall to other uses of vim.treesitter.get_parser --- lua/nvim-ts-autotag/internal.lua | 8 ++++---- lua/nvim-ts-autotag/utils.lua | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lua/nvim-ts-autotag/internal.lua b/lua/nvim-ts-autotag/internal.lua index fd22124..efe5892 100644 --- a/lua/nvim-ts-autotag/internal.lua +++ b/lua/nvim-ts-autotag/internal.lua @@ -243,8 +243,8 @@ local function check_close_tag(close_slash_tag) end M.close_tag = function() - local buf_parser = vim.treesitter.get_parser() - if not buf_parser then + local ok, buf_parser = pcall(vim.treesitter.get_parser) + if not ok then return end buf_parser:parse(true) @@ -256,8 +256,8 @@ M.close_tag = function() end M.close_slash_tag = function() - local buf_parser = vim.treesitter.get_parser() - if not buf_parser then + local ok, buf_parser = pcall(vim.treesitter.get_parser) + if not ok then return end buf_parser:parse(true) diff --git a/lua/nvim-ts-autotag/utils.lua b/lua/nvim-ts-autotag/utils.lua index fb3e85d..ab5e276 100644 --- a/lua/nvim-ts-autotag/utils.lua +++ b/lua/nvim-ts-autotag/utils.lua @@ -65,8 +65,8 @@ M.get_node_at_cursor = function(winnr) local row, col = unpack(vim.api.nvim_win_get_cursor(winnr)) row = row - 1 local buf = vim.api.nvim_win_get_buf(winnr) - local root_lang_tree = vim.treesitter.get_parser(buf) - if not root_lang_tree then + local ok, root_lang_tree = pcall(vim.treesitter.get_parser, buf) + if not ok then return end