From e40e1f45d843507e010d52054bbe4d6dd7961c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 27 Oct 2026 03:39:51 +0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(nvim):=20move=20t?= =?UTF-8?q?reesitter=20to=20the=20new=20nvim-treesitter=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The main branch dropped nvim-treesitter.configs. Start highlighting and indent per buffer on FileType instead, installing a missing parser on first use (the old auto_install behaviour). --- .config/nvim/lua/plugins/nvim-treesitter.lua | 34 +++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/.config/nvim/lua/plugins/nvim-treesitter.lua b/.config/nvim/lua/plugins/nvim-treesitter.lua index 9ce5f78..25774cc 100644 --- a/.config/nvim/lua/plugins/nvim-treesitter.lua +++ b/.config/nvim/lua/plugins/nvim-treesitter.lua @@ -1,11 +1,37 @@ return { "nvim-treesitter/nvim-treesitter", + lazy = false, build = ":TSUpdate", config = function() - require("nvim-treesitter.configs").setup({ - auto_install = true, - highlight = { enable = true }, - indent = { enable = true }, + local ts = require("nvim-treesitter") + local available = {} + for _, lang in ipairs(ts.get_available()) do + available[lang] = true + end + + local function enable(buf) + if not vim.api.nvim_buf_is_valid(buf) or not pcall(vim.treesitter.start, buf) then + return + end + vim.bo[buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + end + + vim.api.nvim_create_autocmd("FileType", { + callback = function(args) + local lang = vim.treesitter.language.get_lang(args.match) + if not lang or not available[lang] then + return + end + if vim.list_contains(ts.get_installed(), lang) then + enable(args.buf) + else + ts.install(lang):await(function() + vim.schedule(function() + enable(args.buf) + end) + end) + end + end, }) end, }