Rewrite nvim-treesitter config for new main-branch API
The nvim-treesitter rewrite removed nvim-treesitter.configs entirely.
Now uses require('nvim-treesitter').install() and a FileType autocmd
for dynamic attach, mirroring current kickstart.nvim.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -257,17 +257,36 @@ require('lazy').setup({
|
||||
--------------------------------------------------------------------------
|
||||
{
|
||||
'nvim-treesitter/nvim-treesitter',
|
||||
build = ':TSUpdate',
|
||||
lazy = false,
|
||||
build = ':TSUpdate',
|
||||
branch = 'main',
|
||||
config = function()
|
||||
require('nvim-treesitter.configs').setup({
|
||||
ensure_installed = (function()
|
||||
local t = { 'bash', 'json', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'vim', 'vimdoc', 'yaml' }
|
||||
vim.list_extend(t, _lang.parsers or {})
|
||||
return t
|
||||
end)(),
|
||||
auto_install = true,
|
||||
highlight = { enable = true },
|
||||
indent = { enable = true },
|
||||
local parsers = { 'bash', 'json', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'vim', 'vimdoc', 'yaml' }
|
||||
vim.list_extend(parsers, _lang.parsers or {})
|
||||
require('nvim-treesitter').install(parsers)
|
||||
|
||||
local function try_attach(buf, lang)
|
||||
if not vim.treesitter.language.add(lang) then return end
|
||||
vim.treesitter.start(buf, lang)
|
||||
if vim.treesitter.query.get(lang, 'indents') then
|
||||
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||
end
|
||||
end
|
||||
|
||||
local available = require('nvim-treesitter').get_available()
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
callback = function(args)
|
||||
local lang = vim.treesitter.language.get_lang(args.match)
|
||||
if not lang then return end
|
||||
local installed = require('nvim-treesitter').get_installed 'parsers'
|
||||
if vim.tbl_contains(installed, lang) then
|
||||
try_attach(args.buf, lang)
|
||||
elseif vim.tbl_contains(available, lang) then
|
||||
require('nvim-treesitter').install(lang):await(function() try_attach(args.buf, lang) end)
|
||||
else
|
||||
try_attach(args.buf, lang)
|
||||
end
|
||||
end,
|
||||
})
|
||||
end,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user