feat(treesitter): add ensure_installed_map

This commit is contained in:
Binh Tran 2024-12-17 00:39:31 +07:00
parent d0251155ab
commit 67f79c9c2d

View file

@ -38,31 +38,32 @@ return {
opts = { opts = {
highlight = { enable = true }, highlight = { enable = true },
indent = { enable = true }, indent = { enable = true },
ensure_installed = { ensure_installed = {},
"bash", ensure_installed_map = {
"c", bash = true,
"diff", c = true,
"html", diff = true,
"javascript", html = true,
"jsdoc", javascript = true,
"json", jsdoc = true,
"jsonc", json = true,
"lua", jsonc = true,
"luadoc", lua = true,
"luap", luadoc = true,
"markdown", luap = true,
"markdown_inline", markdown = true,
"printf", markdown_inline = true,
"python", printf = true,
"query", python = true,
"regex", query = true,
"toml", regex = true,
"tsx", toml = true,
"typescript", tsx = true,
"vim", typescript = true,
"vimdoc", vim = true,
"xml", vimdoc = true,
"yaml", xml = true,
yaml = true,
}, },
incremental_selection = { incremental_selection = {
enable = true, enable = true,
@ -85,9 +86,28 @@ return {
}, },
---@param opts TSConfig ---@param opts TSConfig
config = function(_, opts) config = function(_, opts)
local ensure_installed = nil
if type(opts.ensure_installed) == "table" then if type(opts.ensure_installed) == "table" then
opts.ensure_installed = LazyVim.dedup(opts.ensure_installed) ensure_installed = {}
for _, x in ipairs(opts.ensure_installed) do
ensure_installed[x] = true
end end
end
if type(opts.ensure_installed_map) == "table" then
ensure_installed = vim.tbl_extend("force", ensure_installed or {}, opts.ensure_installed_map)
end
if ensure_installed ~= nil then
opts.ensure_installed = {}
for item, enabled in pairs(ensure_installed) do
if enabled then
table.insert(opts.ensure_installed, item)
end
end
end
-- Remove unofficial opts
opts.ensure_installed_map = nil
require("nvim-treesitter.configs").setup(opts) require("nvim-treesitter.configs").setup(opts)
end, end,
}, },