local auto = require 'std.auto' local ignored = require 'std.ignored' local table = require 'std.table' auto 'look_for_treesitter_parser' { description = 'Try loading a treesitter parser, if available.', events = 'FileType', pattern = '*', command = function ( data ) local match = data.match if table.contains( ignored.filetypes, match ) then vim.notify( 'Ingore ' .. match .. ' for treesitter.' ) return end -- try highlights local ok, err = pcall( vim.treesitter.start ) if not ok then local available = require 'nvim-treesitter.parsers' local potential_parser = available[match] if potential_parser then vim.notify( 'Found potential treesitter parser for current filetype. Trying to install it. ' .. match ) -- TSInstall/TSUpdate seems borked? -- vim.cmd.TSInstall( match ) else vim.notify( err, vim.log.levels.ERROR ) end return end -- indents vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" -- folds, even though i do not care... vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()' end, } -- old code from nvim-treesitter master -- -- if config.auto_install then -- vim.api.nvim_create_autocmd('FileType', { -- callback = function(args) -- local buf = args.buf --- @type integer -- local ft = vim.bo[buf].filetype -- local lang = vim.treesitter.language.get_lang(ft) or ft -- if -- require('nvim-treesitter.parsers')[lang] -- and not vim.list_contains(M.installed_parsers(), lang) -- and not vim.list_contains(config.ignore_install, lang) -- then -- require('nvim-treesitter.install').install(lang, nil, function() -- -- Need to pcall since 'FileType' can be triggered multiple times -- -- per buffer -- pcall(vim.treesitter.start, buf, lang) -- end) -- end -- end, -- }) -- end