diff --git a/docs/manual/release-notes/rl-0.9.md b/docs/manual/release-notes/rl-0.9.md index a6e5dfd6..8246520b 100644 --- a/docs/manual/release-notes/rl-0.9.md +++ b/docs/manual/release-notes/rl-0.9.md @@ -390,4 +390,12 @@ https://github.com/gorbit99/codewindow.nvim - Add razor support for `roslyn_ls` and `csharp_ls` +[mputz86](https://github.com/mputz86) + +- Add `vim.treesitter.indent.pattern` to specify file pattern(s) for which + treesitter indentation should be used +- Add `vim.treesitter.indent.excludes` to exclude filetypes from the treesitter + indentation; e.g. useful for Haskell and PureScript, for which treesitter + indentation does not work good + diff --git a/modules/plugins/treesitter/config.nix b/modules/plugins/treesitter/config.nix index 1ca628b0..e937ae32 100644 --- a/modules/plugins/treesitter/config.nix +++ b/modules/plugins/treesitter/config.nix @@ -4,8 +4,10 @@ ... }: let inherit (lib.modules) mkIf; + inherit (lib.strings) optionalString; inherit (lib.lists) optionals; inherit (lib.nvim.dag) entryAfter; + inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.treesitter; in { @@ -39,8 +41,14 @@ in { -- Enable treesitter highlighting for all filetypes vim.api.nvim_create_autocmd("FileType", { group = "nvf_treesitter", - pattern = "*", - callback = function() + pattern = ${toLuaObject cfg.indent.pattern}, + callback = function(args) + ${optionalString (builtins.length cfg.indent.excludes > 0) '' + local ft = vim.bo[args.buf].filetype + if vim.tbl_contains(${toLuaObject cfg.indent.excludes}, ft) then + return + end + ''} vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" end, }) diff --git a/modules/plugins/treesitter/treesitter.nix b/modules/plugins/treesitter/treesitter.nix index a25c1d3f..ba5b269e 100644 --- a/modules/plugins/treesitter/treesitter.nix +++ b/modules/plugins/treesitter/treesitter.nix @@ -4,7 +4,7 @@ ... }: let inherit (lib.options) mkOption mkEnableOption literalExpression; - inherit (lib.types) listOf nullOr package bool; + inherit (lib.types) listOf nullOr package bool str oneOf; in { options.vim.treesitter = { enable = mkEnableOption "treesitter, also enabled automatically through language options"; @@ -64,7 +64,28 @@ in { ''; }; - indent = {enable = mkEnableOption "indentation with treesitter" // {default = true;};}; + indent = { + enable = mkEnableOption "indentation with treesitter" // {default = true;}; + pattern = mkOption { + type = oneOf [str (listOf str)]; + default = "*"; + example = literalExpression ''["lua" "nix"]''; + description = '' + Specify the filetype pattern(s) for which the treesitter indentation should be used. + + See {command}`:h autocmd-pattern`. + ''; + }; + excludes = mkOption { + type = listOf str; + default = []; + example = literalExpression ''["haskell", "purescript"]''; + description = '' + Exclude the listed filetypes from using treesitter indentation. + ''; + }; + }; + highlight = {enable = mkEnableOption "highlighting with treesitter" // {default = true;};}; }; }