diff --git a/.config/nvim/lua/plugin/nvim-treesitter.lua b/.config/nvim/lua/plugin/nvim-treesitter.lua index 64f9b0d..4ac89e1 100644 --- a/.config/nvim/lua/plugin/nvim-treesitter.lua +++ b/.config/nvim/lua/plugin/nvim-treesitter.lua @@ -6,16 +6,31 @@ return { { lazy = false, config = function() -- Pre-install a few languages we're (very) likely going to use - require('nvim-treesitter').install({ + local ts = require('nvim-treesitter') + ts.install({ 'c', 'make', 'bash', 'gitignore', 'editorconfig', 'ini', 'json', 'yaml', }) + + -- Define aliases for entries that lack an entry, but should have one. + local alias = { + { 'sh', 'bash' }, + } + + local pat = vim.iter(alias):map(function(a) return a[1] end):totable() + vim.list_extend(pat, ts.get_available()) Autocmd('FileType', { - pattern = require('nvim-treesitter').get_available(), - callback = function(ft) - require('nvim-treesitter').install(ft.match) - pcall(vim.treesitter.start) + pattern = pat, + callback = function(arg) + local a = vim.iter(alias) + :find(function(a) return arg.match == a[1] end) + if not a then -- Ensure we only install if an alias was found + require('nvim-treesitter').install(vim.bo.ft) + pcall(vim.treesitter.start) + return + end + vim.bo.ft = a[2] -- Retriggers function end }) end,