@@ -888,27 +888,36 @@ require('lazy').setup({
888888 branch = ' main' ,
889889 -- [[ Configure Treesitter ]] See `:help nvim-treesitter-intro`
890890 config = function ()
891- local filetypes = { ' bash' , ' c' , ' diff' , ' html' , ' lua' , ' luadoc' , ' markdown' , ' markdown_inline' , ' query' , ' vim' , ' vimdoc' , ' python' }
892- require (' nvim-treesitter' ).install (filetypes )
891+ -- ensure basic parser are installed
892+ local parsers = { ' bash' , ' c' , ' diff' , ' html' , ' lua' , ' luadoc' , ' markdown' , ' markdown_inline' , ' query' , ' vim' , ' vimdoc' }
893+ require (' nvim-treesitter' ).install (parsers )
894+
895+ --- @param buf integer
896+ --- @param language string
897+ local function treesitter_try_attach (buf , language )
898+ -- check if parser exists and load it
899+ if not vim .treesitter .language .add (language ) then return end
900+ -- enables syntax highlighting and other treesitter features
901+ vim .treesitter .start (buf , language )
902+
903+ -- enables treesitter based folds
904+ -- for more info on folds see `:help folds`
905+ -- vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
906+ -- vim.wo.foldmethod = 'expr'
907+
908+ -- enables treesitter based indentation
909+ vim .bo .indentexpr = " v:lua.require'nvim-treesitter'.indentexpr()"
910+ end
911+
912+ local available_parsers = require (' nvim-treesitter' ).get_available ()
893913 vim .api .nvim_create_autocmd (' FileType' , {
894914 callback = function (args )
895915 local buf , filetype = args .buf , args .match
896916
897917 local language = vim .treesitter .language .get_lang (filetype )
898918 if not language then return end
899919
900- -- check if parser exists and load it
901- if not vim .treesitter .language .add (language ) then return end
902- -- enables syntax highlighting and other treesitter features
903- vim .treesitter .start (buf , language )
904-
905- -- enables treesitter based folds
906- -- for more info on folds see `:help folds`
907- -- vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
908- -- vim.wo.foldmethod = 'expr'
909-
910- -- enables treesitter based indentation
911- vim .bo .indentexpr = " v:lua.require'nvim-treesitter'.indentexpr()"
920+ treesitter_try_attach (buf , language )
912921 end ,
913922 })
914923 end ,
0 commit comments