mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-21 20:11:06 +00:00
feat(treesitter): added support for disable langs to indent/highlight/folds. Closes #6608
This commit is contained in:
parent
4efd0e2bea
commit
0e8069c78e
1 changed files with 18 additions and 7 deletions
|
|
@ -21,12 +21,13 @@ return {
|
||||||
event = { "LazyFile", "VeryLazy" },
|
event = { "LazyFile", "VeryLazy" },
|
||||||
cmd = { "TSUpdate", "TSInstall", "TSLog", "TSUninstall" },
|
cmd = { "TSUpdate", "TSInstall", "TSLog", "TSUninstall" },
|
||||||
opts_extend = { "ensure_installed" },
|
opts_extend = { "ensure_installed" },
|
||||||
|
---@alias lazyvim.TSFeat { enable?: boolean, disable?: string[] }
|
||||||
---@class lazyvim.TSConfig: TSConfig
|
---@class lazyvim.TSConfig: TSConfig
|
||||||
opts = {
|
opts = {
|
||||||
-- LazyVim config for treesitter
|
-- LazyVim config for treesitter
|
||||||
indent = { enable = true },
|
indent = { enable = true }, ---@type lazyvim.TSFeat
|
||||||
highlight = { enable = true },
|
highlight = { enable = true }, ---@type lazyvim.TSFeat
|
||||||
folds = { enable = true },
|
folds = { enable = true }, ---@type lazyvim.TSFeat
|
||||||
ensure_installed = {
|
ensure_installed = {
|
||||||
"bash",
|
"bash",
|
||||||
"c",
|
"c",
|
||||||
|
|
@ -99,22 +100,32 @@ return {
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
group = vim.api.nvim_create_augroup("lazyvim_treesitter", { clear = true }),
|
group = vim.api.nvim_create_augroup("lazyvim_treesitter", { clear = true }),
|
||||||
callback = function(ev)
|
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
|
return
|
||||||
end
|
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
|
-- highlighting
|
||||||
if vim.tbl_get(opts, "highlight", "enable") ~= false then
|
if enabled("highlight", "highlights") then
|
||||||
pcall(vim.treesitter.start)
|
pcall(vim.treesitter.start)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- indents
|
-- 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()")
|
LazyVim.set_default("indentexpr", "v:lua.LazyVim.treesitter.indentexpr()")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- folds
|
-- 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
|
if LazyVim.set_default("foldmethod", "expr") then
|
||||||
LazyVim.set_default("foldexpr", "v:lua.LazyVim.treesitter.foldexpr()")
|
LazyVim.set_default("foldexpr", "v:lua.LazyVim.treesitter.foldexpr()")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue