Fix treesitter again

This commit is contained in:
Thomas Avé 2025-12-19 16:30:48 +01:00
parent 435d6f5822
commit 9de92b3c62
2 changed files with 16 additions and 16 deletions

View File

@ -35,9 +35,9 @@ in
wayland.windowManager.hyprland.settings = {
monitor = [
"eDP-1,2880x1800@120.00Hz,480x0,1.2,vrr,1"
"DP-1,1920x1080,6240x500,1"
"HDMI-A-1,3840x2160@60.00Hz,0x-2160,1"
"DP-3,1920x1080,3840x-540,1"
"DP-1,1920x1080,3840x-540,1"
];
bind = [
", XF86PowerOff, exec, ${pkgs.rofi}/bin/rofi -show power-menu -modi power-menu:${

View File

@ -1,6 +1,6 @@
return {
'nvim-treesitter/nvim-treesitter',
-- branch = 'main', -- This is the default now
branch = 'main',
lazy = false,
config = function()
-- 1. Install Parsers
@ -10,28 +10,28 @@ return {
"rust", "sql", "yaml", "markdown", "markdown_inline", "nix", "bibtex"
})
-- 2. Enable Highlighting via Autocmd
-- 2. Safe Autocmd for Highlighting & Indent
vim.api.nvim_create_autocmd('FileType', {
callback = function(args)
-- Disable logic (ini, markdown, or large files)
local ft = vim.bo[args.buf].filetype
if ft == "ini" or ft == "markdown" then return end
-- 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
-- Enable highlighting
vim.treesitter.start()
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)
-- 3. Enable Indentation
vim.api.nvim_create_autocmd('FileType', {
pattern = '*',
callback = function()
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
-- 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,
}