M.toggle_boolean_value_on_line = function()
local ts_utils = require("nvim-tressitter-ts.utils")
local line = vim.api.nvim_get_current_line()
local booleans = ts_utils.get_all_tokens_of_type(line, "boolean")
local cursor_pos = vim.api.nvim_win_get_cursor(0)[1]
if #booleans == 1 then
booleans[1].value = not booleans[1].value
else
for i, boolean in ipairs(booleans) do
if cursor_pos == boolean.range.start then
boolean.value = not boolean.value
break
end
end
end
end
Use pcall
local ok, ts_utils = pcall(require, "nvim-treesitter-ts.utils")
if not ok then
return
end