From 87fc61f065db61e3e229b08765e2ea030c0eaf61 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Mon, 20 May 2024 23:38:13 +0200 Subject: [PATCH] fix: dont error when treesitter parser is not available --- lua/ts-comments.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/ts-comments.lua b/lua/ts-comments.lua index c4d5d5a..6603625 100644 --- a/lua/ts-comments.lua +++ b/lua/ts-comments.lua @@ -46,12 +46,12 @@ function M.setup(opts) if option ~= "commentstring" then return get_option(filetype, option) end - local lang = vim.treesitter.language.get_lang(filetype) + local lang = vim.treesitter.language.get_lang(filetype) or filetype local ret = opts.lang[lang] if type(ret) == "table" then - local node = vim.treesitter.get_node({ ignore_injections = false }) - while node do + local ok, node = pcall(vim.treesitter.get_node, { ignore_injections = false }) + while ok and node do if ret[node:type()] then ret = ret[node:type()] break