mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-12-25 12:14:19 +01:00
feat(treesitter): added support for disable langs to indent/highlight/folds. Closes #6608
This commit is contained in:
@@ -21,12 +21,13 @@ return {
|
||||
event = { "LazyFile", "VeryLazy" },
|
||||
cmd = { "TSUpdate", "TSInstall", "TSLog", "TSUninstall" },
|
||||
opts_extend = { "ensure_installed" },
|
||||
---@alias lazyvim.TSFeat { enable?: boolean, disable?: string[] }
|
||||
---@class lazyvim.TSConfig: TSConfig
|
||||
opts = {
|
||||
-- LazyVim config for treesitter
|
||||
indent = { enable = true },
|
||||
highlight = { enable = true },
|
||||
folds = { enable = true },
|
||||
indent = { enable = true }, ---@type lazyvim.TSFeat
|
||||
highlight = { enable = true }, ---@type lazyvim.TSFeat
|
||||
folds = { enable = true }, ---@type lazyvim.TSFeat
|
||||
ensure_installed = {
|
||||
"bash",
|
||||
"c",
|
||||
@@ -99,22 +100,32 @@ return {
|
||||
vim.api.nvim_create_autocmd("FileType", {
|
||||
group = vim.api.nvim_create_augroup("lazyvim_treesitter", { clear = true }),
|
||||
callback = function(ev)
|
||||
if not LazyVim.treesitter.have(ev.match) then
|
||||
local ft, lang = ev.match, vim.treesitter.language.get_lang(ev.match)
|
||||
if not LazyVim.treesitter.have(ft) then
|
||||
return
|
||||
end
|
||||
|
||||
---@param feat string
|
||||
---@param query string
|
||||
local function enabled(feat, query)
|
||||
local f = opts[feat] or {} ---@type lazyvim.TSFeat
|
||||
return f.enable ~= false
|
||||
and not vim.tbl_contains(f.disable or {}, lang)
|
||||
and LazyVim.treesitter.have(ft, query)
|
||||
end
|
||||
|
||||
-- highlighting
|
||||
if vim.tbl_get(opts, "highlight", "enable") ~= false then
|
||||
if enabled("highlight", "highlights") then
|
||||
pcall(vim.treesitter.start)
|
||||
end
|
||||
|
||||
-- indents
|
||||
if vim.tbl_get(opts, "indent", "enable") ~= false and LazyVim.treesitter.have(ev.match, "indents") then
|
||||
if enabled("indent", "indents") then
|
||||
LazyVim.set_default("indentexpr", "v:lua.LazyVim.treesitter.indentexpr()")
|
||||
end
|
||||
|
||||
-- folds
|
||||
if vim.tbl_get(opts, "folds", "enable") ~= false and LazyVim.treesitter.have(ev.match, "folds") then
|
||||
if enabled("folds", "folds") then
|
||||
if LazyVim.set_default("foldmethod", "expr") then
|
||||
LazyVim.set_default("foldexpr", "v:lua.LazyVim.treesitter.foldexpr()")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user