-
hi im tryin to make a treesitter component that updates when local TreesitterActive = {
condition = function()
local ts_avail, ts = pcall(require, "nvim-treesitter.parsers")
return ts_avail and ts.has_parser()
end,
-- update = { "BufWinEnter", "ModeChanged" },
update = { "ModeChanged" },
provider = function()
-- local ts_avail, ts = pcall(require, "nvim-treesitter.parsers")
-- return (ts_avail and ts.has_parser()) and "綠TS" or ""
local buf = vim.api.nvim_get_current_buf()
local highlighter = require("vim.treesitter.highlighter")
return highlighter.active[buf] and "綠TS " or ""
end,
hl = { fg = "green", bold = false },
} is this efficient? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
I think there's no need to check if TS is installed each time the status line is refreshed. Instead, you could check it only once outside the component. The valid update autocmd would be local ts_avail, ts = pcall(require, "nvim-treesitter.parsers")
local TreesitterActive = {
update = {
"OptionSet",
pattern = "syntax"
}
provider = function()
if not (ts_avail and ts.has_parser()) then return end
local buf = vim.api.nvim_get_current_buf()
local highlighter = require("vim.treesitter.highlighter")
return highlighter.active[buf] and "綠TS " or ""
end,
hl = { fg = "green", bold = false },
} |
Beta Was this translation helpful? Give feedback.
I think there's no need to check if TS is installed each time the status line is refreshed. Instead, you could check it only once outside the component. The valid update autocmd would be
OptionSet syntax
. Because conditions are evaluated regardless of a valid cache, you can also move the condition inside the provider to remove any operation on component evaluation.