58 lines
1.8 KiB
Lua
58 lines
1.8 KiB
Lua
return {
|
|
'nvim-treesitter/nvim-treesitter',
|
|
branch = 'main',
|
|
lazy = false,
|
|
build = ':TSUpdate',
|
|
config = function()
|
|
-- Old `ensure_installed`
|
|
require('nvim-treesitter').install({
|
|
-- Neovim config
|
|
'lua', 'vim', 'vimdoc', 'query',
|
|
|
|
-- Rust
|
|
'rust', 'toml',
|
|
|
|
-- Ansible
|
|
'yaml',
|
|
|
|
-- Frontend stuff
|
|
'html', 'css', 'javascript', 'typescript', 'tsx', 'json',
|
|
|
|
-- Low level stuff
|
|
'c', 'asm',
|
|
})
|
|
|
|
-- Old `auto_install`
|
|
local ts_autoinstall_group = vim.api.nvim_create_augroup('TSAutoInstall', { clear = true })
|
|
vim.api.nvim_create_autocmd('FileType', {
|
|
group = ts_autoinstall_group,
|
|
callback = function(args)
|
|
local lang = vim.treesitter.language.get_lang(args.match) or args.match
|
|
|
|
-- Try starting right away: if it works, the parser was already installed
|
|
if pcall(vim.treesitter.start, args.buf, lang) then
|
|
return
|
|
end
|
|
|
|
-- Didn't work: download the parser in the background
|
|
local ok = pcall(function()
|
|
require('nvim-treesitter').install({ lang }, { summary = false })
|
|
end)
|
|
if not ok then return end
|
|
|
|
-- Poll (non-blocking) until start() succeeds, or give up after 9s
|
|
local function try_start(attempts)
|
|
attempts = attempts or 0
|
|
if pcall(vim.treesitter.start, args.buf, lang) then
|
|
return
|
|
elseif attempts < 30 then
|
|
vim.defer_fn(function() try_start(attempts + 1) end, 300)
|
|
end
|
|
end
|
|
try_start()
|
|
end,
|
|
})
|
|
end,
|
|
}
|
|
|