return { 'nvim-treesitter/nvim-treesitter', branch = 'main', lazy = false, config = function() -- 1. Install Parsers require('nvim-treesitter').install({ "typst", "cpp", "c", "lua", "vim", "dockerfile", "python", "java", "cmake", "diff", "gitcommit", "html", "css", "javascript", "json", "rust", "sql", "yaml", "markdown", "markdown_inline", "nix", "bibtex" }) -- 2. Safe Autocmd for Highlighting & Indent vim.api.nvim_create_autocmd('FileType', { callback = function(args) -- Get the language associated with the filetype local lang = vim.treesitter.language.get_lang(vim.bo[args.buf].filetype) if not lang then return end -- IGNORE specific filetypes or large files if lang == "ini" then return end local max_filesize = 2000 * 1024 -- 2MB local ok, stats = pcall(vim.uv.fs_stat, vim.api.nvim_buf_get_name(args.buf)) if ok and stats and stats.size > max_filesize then return end -- SAFEGUARD: Try to start. If it fails (e.g., 'snacks_layout_box'), 'success' will be false. local success, _ = pcall(vim.treesitter.start, args.buf, lang) -- Only enable indentation if Treesitter actually started successfully if success then vim.bo[args.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" end end, }) end, }