From f9056452ee29f8d58bcdf37032761e5a5ae81ad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Uruba?= Date: Mon, 4 May 2026 17:08:15 +0200 Subject: [PATCH] nvim: Update treesitter config to nvim 0.12 --- .../nvim/lua/lazy-plugins/lsp-treesitter.lua | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/nvim/.config/nvim/lua/lazy-plugins/lsp-treesitter.lua b/nvim/.config/nvim/lua/lazy-plugins/lsp-treesitter.lua index 5107aa0..f56bcf9 100644 --- a/nvim/.config/nvim/lua/lazy-plugins/lsp-treesitter.lua +++ b/nvim/.config/nvim/lua/lazy-plugins/lsp-treesitter.lua @@ -3,36 +3,14 @@ return { "nvim-treesitter/nvim-treesitter", branch = "main", lazy = false, - event = { - "BufReadPre", - "BufNewFile", - }, main = "nvim-treesitter", build = ":TSUpdate", dependencies = { "windwp/nvim-ts-autotag", }, config = function() - require("nvim-treesitter").setup({ - highlight = { - enable = true, - }, - indent = { - enable = true, - }, - autotag = { - enable = true, - }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = "", - node_incremental = "", - scope_incremental = false, - node_decremental = "", - }, - }, - }) + require("nvim-treesitter").setup() + require("nvim-ts-autotag").setup() local parsers = { "bash", @@ -54,16 +32,34 @@ return { "markdown_inline", "php", "svelte", + "tsx", "twig", + "typescript", "vim", "yaml", } - for _, lang in ipairs(parsers) do - if not pcall(vim.treesitter.language.inspect, lang) then - vim.cmd("TSInstall " .. lang) - end + 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 + return + end + pcall(vim.treesitter.start, args.buf, lang) + vim.bo[args.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + end, + }) end, }, {