From 32c2052acd01fde69201bd5ea58aa8a41554d5b2 Mon Sep 17 00:00:00 2001 From: Heitor Augusto <44377258+HeitorAugustoLN@users.noreply.github.com> Date: Thu, 8 Jan 2026 16:08:19 -0300 Subject: [PATCH 1/2] treesitter: add compatibility layer for master --- modules/plugins/treesitter/config.nix | 44 +++++++++++++++------------ 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index 899e7c190..601efa4f3 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -24,27 +24,33 @@ in { pluginRC.treesitter-autocommands = entryAfter ["basic"] '' vim.api.nvim_create_augroup("nvf_treesitter", { clear = true }) - ${lib.optionalString cfg.highlight.enable '' - -- Enable treesitter highlighting for all filetypes - vim.api.nvim_create_autocmd("FileType", { - group = "nvf_treesitter", - pattern = "*", - callback = function() - pcall(vim.treesitter.start) - end, - }) - ''} + local has_configs_module = pcall(require, 'nvim-treesitter.configs') - ${lib.optionalString cfg.indent.enable '' - -- Enable treesitter highlighting for all filetypes - vim.api.nvim_create_autocmd("FileType", { - group = "nvf_treesitter", - pattern = "*", - callback = function() - vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" - end, + if has_configs_module then + -- nvim-treesitter master branch + require('nvim-treesitter.configs').setup({ + ${lib.optionalString cfg.highlight.enable '' + highlight = { enable = true }, + ''}${lib.optionalString cfg.indent.enable '' + indent = { enable = true }, + ''} }) - ''} + else + -- nvim-treesitter main branch + ${lib.optionalString (cfg.highlight.enable || cfg.indent.enable) '' + vim.api.nvim_create_autocmd("FileType", { + group = "nvf_treesitter", + pattern = "*", + callback = function() + ${lib.optionalString cfg.highlight.enable '' + pcall(vim.treesitter.start) + ''}${lib.optionalString cfg.indent.enable '' + vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + ''} + end, + }) + ''} + end ${lib.optionalString cfg.fold '' -- Enable treesitter folding for all filetypes From 8d7f0c37a6da045860eb06fd467aec3401f247cb Mon Sep 17 00:00:00 2001 From: Heitor Augusto <44377258+HeitorAugustoLN@users.noreply.github.com> Date: Thu, 8 Jan 2026 16:15:05 -0300 Subject: [PATCH 2/2] treesitter: add setupOpts For covering missing options for master, and for main branch just in case someone wants to change the install dir --- docs/manual/release-notes/rl-0.9.md | 3 +- modules/plugins/treesitter/config.nix | 37 ++++++++++++----------- modules/plugins/treesitter/treesitter.nix | 3 ++ 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index ce8f6232e..a7a9d8a50 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -39,4 +39,5 @@ [jtliang24](https://github.com/jtliang24): -- Updated nix language plugin to use pkgs.nixfmt instead of pkgs.nixfmt-rfc-style +- Updated nix language plugin to use pkgs.nixfmt instead of + pkgs.nixfmt-rfc-style diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index 601efa4f3..e08971a3d 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -28,28 +28,31 @@ in { if has_configs_module then -- nvim-treesitter master branch - require('nvim-treesitter.configs').setup({ + require('nvim-treesitter.configs').setup(vim.tbl_deep_extend("force", { ${lib.optionalString cfg.highlight.enable '' - highlight = { enable = true }, - ''}${lib.optionalString cfg.indent.enable '' - indent = { enable = true }, - ''} - }) + highlight = { enable = true }, + ''}${lib.optionalString cfg.indent.enable '' + indent = { enable = true }, + ''} + }, ${lib.nvim.lua.toLuaObject cfg.setupOpts})) else -- nvim-treesitter main branch + ${lib.optionalString (cfg.setupOpts != {}) '' + require('nvim-treesitter').setup(${lib.nvim.lua.toLuaObject cfg.setupOpts}) + ''} ${lib.optionalString (cfg.highlight.enable || cfg.indent.enable) '' - vim.api.nvim_create_autocmd("FileType", { - group = "nvf_treesitter", - pattern = "*", - callback = function() - ${lib.optionalString cfg.highlight.enable '' - pcall(vim.treesitter.start) - ''}${lib.optionalString cfg.indent.enable '' - vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" - ''} - end, - }) + vim.api.nvim_create_autocmd("FileType", { + group = "nvf_treesitter", + pattern = "*", + callback = function() + ${lib.optionalString cfg.highlight.enable '' + pcall(vim.treesitter.start) + ''}${lib.optionalString cfg.indent.enable '' + vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" ''} + end, + }) + ''} end ${lib.optionalString cfg.fold '' diff --git a/modules/plugins/treesitter/treesitter.nix b/modules/plugins/treesitter/treesitter.nix index c2039a9fa..8edb7b194 100644 --- a/modules/plugins/treesitter/treesitter.nix +++ b/modules/plugins/treesitter/treesitter.nix @@ -5,6 +5,7 @@ }: let inherit (lib.options) mkOption mkEnableOption literalExpression; inherit (lib.types) listOf package bool; + inherit (lib.nvim.types) mkPluginSetupOption; in { options.vim.treesitter = { enable = mkEnableOption "treesitter, also enabled automatically through language options"; @@ -66,5 +67,7 @@ in { indent = {enable = mkEnableOption "indentation with treesitter" // {default = true;};}; highlight = {enable = mkEnableOption "highlighting with treesitter" // {default = true;};}; + + setupOpts = mkPluginSetupOption "nvim-treesitter" {}; }; }