@@ -19,6 +19,9 @@ import TabItem from '@theme/TabItem';
1919``` lua
2020opts = {
2121 -- LazyVim config for treesitter
22+ indent = { enable = true },
23+ highlight = { enable = true },
24+ folds = { enable = true },
2225 ensure_installed = {
2326 " bash" ,
2427 " c" ,
@@ -64,7 +67,9 @@ opts = {
6467 LazyVim .error (" Please restart Neovim and run `:TSUpdate` to use the `nvim-treesitter` **main** branch." )
6568 return
6669 end
67- TS .update (nil , { summary = true })
70+ LazyVim .treesitter .ensure_treesitter_cli (function ()
71+ TS .update (nil , { summary = true })
72+ end )
6873 end ,
6974 lazy = vim .fn .argc (- 1 ) == 0 , -- load treesitter early when opening a file from the cmdline
7075 event = { " LazyFile" , " VeryLazy" },
@@ -73,6 +78,9 @@ opts = {
7378 --- @class lazyvim.TSConfig : TSConfig
7479 opts = {
7580 -- LazyVim config for treesitter
81+ indent = { enable = true },
82+ highlight = { enable = true },
83+ folds = { enable = true },
7684 ensure_installed = {
7785 " bash" ,
7886 " c" ,
@@ -107,44 +115,47 @@ opts = {
107115 -- some quick sanity checks
108116 if not TS .get_installed then
109117 return LazyVim .error (" Please use `:Lazy` and update `nvim-treesitter`" )
110- elseif vim .fn .executable (" tree-sitter" ) == 0 then
111- return LazyVim .error ({
112- " **treesitter-main** requires the `tree-sitter` CLI executable to be installed." ,
113- " Run `:checkhealth nvim-treesitter` for more information." ,
114- })
115118 elseif type (opts .ensure_installed ) ~= " table" then
116119 return LazyVim .error (" `nvim-treesitter` opts.ensure_installed must be a table" )
117120 end
118121
119122 -- setup treesitter
120123 TS .setup (opts )
121-
122124 LazyVim .treesitter .get_installed (true ) -- initialize the installed langs
123125
124126 -- install missing parsers
125127 local install = vim .tbl_filter (function (lang )
126128 return not LazyVim .treesitter .have (lang )
127129 end , opts .ensure_installed or {})
128130 if # install > 0 then
129- TS .install (install , { summary = true }):await (function ()
130- LazyVim .treesitter .get_installed (true ) -- refresh the installed langs
131+ LazyVim .treesitter .ensure_treesitter_cli (function ()
132+ TS .install (install , { summary = true }):await (function ()
133+ LazyVim .treesitter .get_installed (true ) -- refresh the installed langs
134+ end )
131135 end )
132136 end
133137
134- -- treesitter highlighting
135138 vim .api .nvim_create_autocmd (" FileType" , {
136139 group = vim .api .nvim_create_augroup (" lazyvim_treesitter" , { clear = true }),
137140 callback = function (ev )
138- if LazyVim .treesitter .have (ev .match ) then
141+ if not LazyVim .treesitter .have (ev .match ) then
142+ return
143+ end
144+
145+ -- highlighting
146+ if vim .tbl_get (opts , " highlight" , " enable" ) ~= false then
139147 pcall (vim .treesitter .start )
148+ end
140149
141- -- check if ftplugins changed foldexpr/indentexpr
142- for _ , option in ipairs ({ " foldexpr" , " indentexpr" }) do
143- local expr = " v:lua.LazyVim.treesitter." .. option .. " ()"
144- if vim .opt_global [option ]:get () == expr then
145- vim .opt_local [option ] = expr
146- end
147- end
150+ -- indents
151+ if vim .tbl_get (opts , " indent" , " enable" ) ~= false then
152+ vim .bo [ev .buf ].indentexpr = " v:lua.LazyVim.treesitter.indentexpr()"
153+ end
154+
155+ -- folds
156+ if vim .tbl_get (opts , " folds" , " enable" ) ~= false then
157+ vim .wo .foldmethod = " expr"
158+ vim .wo .foldexpr = " v:lua.LazyVim.treesitter.foldexpr()"
148159 end
149160 end ,
150161 })
0 commit comments