@@ -18,6 +18,7 @@ import TabItem from '@theme/TabItem';
1818
1919``` lua
2020opts = {
21+ -- LazyVim config for treesitter
2122 ensure_installed = {
2223 " bash" ,
2324 " c" ,
@@ -69,7 +70,9 @@ opts = {
6970 event = { " LazyFile" , " VeryLazy" },
7071 cmd = { " TSUpdate" , " TSInstall" , " TSLog" , " TSUninstall" },
7172 opts_extend = { " ensure_installed" },
73+ --- @class lazyvim.TSConfig : TSConfig
7274 opts = {
75+ -- LazyVim config for treesitter
7376 ensure_installed = {
7477 " bash" ,
7578 " c" ,
@@ -97,43 +100,39 @@ opts = {
97100 " yaml" ,
98101 },
99102 },
100- --- @param plugin LazyPlugin
101- --- @param opts TSConfig
102- config = function (plugin , opts )
103- if vim .fn .executable (" tree-sitter" ) == 0 then
104- LazyVim .error ({
103+ --- @param opts lazyvim.TSConfig
104+ config = function (_ , opts )
105+ local TS = require (" nvim-treesitter" )
106+
107+ -- some quick sanity checks
108+ if not TS .get_installed then
109+ return LazyVim .error (" Please use `:Lazy` and update `nvim-treesitter`" )
110+ elseif vim .fn .executable (" tree-sitter" ) == 0 then
111+ return LazyVim .error ({
105112 " **treesitter-main** requires the `tree-sitter` CLI executable to be installed." ,
106113 " Run `:checkhealth nvim-treesitter` for more information." ,
107114 })
108- return
109- end
110- if type (opts .ensure_installed ) ~= " table" then
111- LazyVim .error (" `nvim-treesitter` opts.ensure_installed must be a table" )
115+ elseif type (opts .ensure_installed ) ~= " table" then
116+ return LazyVim .error (" `nvim-treesitter` opts.ensure_installed must be a table" )
112117 end
113118
114- local TS = require (" nvim-treesitter" )
115- if not TS .get_installed then
116- LazyVim .error (" Please use `:Lazy` and update `nvim-treesitter`" )
117- return
118- end
119+ -- setup treesitter
119120 TS .setup (opts )
120121
121- local needed = LazyVim .dedup (opts .ensure_installed --[[ @as string[] ]] )
122- LazyVim .ui .installed = TS .get_installed (" parsers" )
123-
122+ -- install missing parsers
124123 local install = vim .tbl_filter (function (lang )
125- return not LazyVim .ui .have (lang )
126- end , needed )
127-
124+ return not LazyVim .treesitter .have (lang )
125+ end , opts .ensure_installed or {})
128126 if # install > 0 then
129127 TS .install (install , { summary = true }):await (function ()
130- LazyVim .ui . installed = TS . get_installed (" parsers " )
128+ LazyVim .treesitter . get_installed (true ) -- refresh the installed langs
131129 end )
132130 end
133131
132+ -- treesitter highlighting
134133 vim .api .nvim_create_autocmd (" FileType" , {
135134 callback = function (ev )
136- if LazyVim .ui .have (ev .match ) then
135+ if LazyVim .treesitter .have (ev .match ) then
137136 pcall (vim .treesitter .start )
138137 end
139138 end ,
0 commit comments