Merge pull request #1520 from mputz86/feat-treesitter-settings
Some checks are pending
Set up binary cache / cachix (default) (push) Waiting to run
Set up binary cache / cachix (maximal) (push) Waiting to run
Set up binary cache / cachix (nix) (push) Waiting to run
Treewide Checks / Validate flake (push) Waiting to run
Treewide Checks / Check formatting (push) Waiting to run
Treewide Checks / Check source tree for typos (push) Waiting to run
Treewide Checks / Validate documentation builds (push) Waiting to run
Treewide Checks / Validate documentation builds-1 (push) Waiting to run
Treewide Checks / Validate documentation builds-2 (push) Waiting to run
Treewide Checks / Validate documentation builds-3 (push) Waiting to run
Treewide Checks / Validate hyperlinks in documentation sources (push) Waiting to run
Treewide Checks / Validate Editorconfig conformance (push) Waiting to run
Build and deploy documentation / Check latest commit (push) Waiting to run
Build and deploy documentation / publish (push) Blocked by required conditions

treesitter: allow setting of filetype pattern and exculdes for indent
This commit is contained in:
Ching Pei Yang 2026-04-16 02:41:40 +02:00 committed by GitHub
commit 2afb8804f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 4 deletions

View file

@ -437,4 +437,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
<!-- vim: set textwidth=80: -->

View file

@ -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,
})

View file

@ -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;};};
};
}