nvim: Update treesitter config to nvim 0.12

This commit is contained in:
2026-05-04 17:08:15 +02:00
parent 47acfd4ff2
commit f9056452ee

View File

@@ -3,36 +3,14 @@ return {
"nvim-treesitter/nvim-treesitter", "nvim-treesitter/nvim-treesitter",
branch = "main", branch = "main",
lazy = false, lazy = false,
event = {
"BufReadPre",
"BufNewFile",
},
main = "nvim-treesitter", main = "nvim-treesitter",
build = ":TSUpdate", build = ":TSUpdate",
dependencies = { dependencies = {
"windwp/nvim-ts-autotag", "windwp/nvim-ts-autotag",
}, },
config = function() config = function()
require("nvim-treesitter").setup({ require("nvim-treesitter").setup()
highlight = { require("nvim-ts-autotag").setup()
enable = true,
},
indent = {
enable = true,
},
autotag = {
enable = true,
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<C-space>",
node_incremental = "<C-space>",
scope_incremental = false,
node_decremental = "<bs>",
},
},
})
local parsers = { local parsers = {
"bash", "bash",
@@ -54,16 +32,34 @@ return {
"markdown_inline", "markdown_inline",
"php", "php",
"svelte", "svelte",
"tsx",
"twig", "twig",
"typescript",
"vim", "vim",
"yaml", "yaml",
} }
for _, lang in ipairs(parsers) do local installed = require("nvim-treesitter.config").get_installed()
local missing = vim.iter(parsers)
:filter(function(p)
return not vim.tbl_contains(installed, p)
end)
:totable()
if #missing > 0 then
require("nvim-treesitter").install(missing)
end
vim.api.nvim_create_autocmd("FileType", {
callback = function(args)
local ft = vim.bo[args.buf].filetype
local lang = vim.treesitter.language.get_lang(ft) or ft
if not pcall(vim.treesitter.language.inspect, lang) then if not pcall(vim.treesitter.language.inspect, lang) then
vim.cmd("TSInstall " .. lang) return
end
end end
pcall(vim.treesitter.start, args.buf, lang)
vim.bo[args.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end,
})
end, end,
}, },
{ {