File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1200,7 +1200,18 @@ require('lazy').setup({
12001200 local language = vim .treesitter .language .get_lang (filetype )
12011201 if not language then return end
12021202
1203- treesitter_try_attach (buf , language )
1203+ local installed_parsers = require (' nvim-treesitter' ).get_installed ' parsers'
1204+
1205+ if vim .tbl_contains (installed_parsers , language ) then
1206+ -- enable the parser if it is installed
1207+ treesitter_try_attach (buf , language )
1208+ elseif vim .tbl_contains (available_parsers , language ) then
1209+ -- if a parser is available in `nvim-treesitter` auto install it, and enable it after the installation is done
1210+ require (' nvim-treesitter' ).install (language ):await (function () treesitter_try_attach (buf , language ) end )
1211+ else
1212+ -- try to enable treesitter features in case the parser exists but is not available from `nvim-treesitter`
1213+ treesitter_try_attach (buf , language )
1214+ end
12041215 end ,
12051216 })
12061217 end ,
You can’t perform that action at this time.
0 commit comments