treesitter: migrate to the new api

This commit is contained in:
Heitor Augusto 2026-01-06 12:45:28 -03:00
commit 27a2953aff
No known key found for this signature in database
GPG key ID: 3EEC05B0024AF8A4
4 changed files with 82 additions and 187 deletions

View file

@ -3,21 +3,12 @@
lib,
...
}: let
inherit (lib.options) mkOption mkEnableOption literalMD literalExpression;
inherit (lib.types) listOf package str either bool;
inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) luaInline;
inherit (lib.options) mkOption mkEnableOption literalExpression;
inherit (lib.types) listOf package bool;
in {
options.vim.treesitter = {
enable = mkEnableOption "treesitter, also enabled automatically through language options";
mappings.incrementalSelection = {
init = mkMappingOption "Init selection [treesitter]" "gnn";
incrementByNode = mkMappingOption "Increment selection by node [treesitter]" "grn";
incrementByScope = mkMappingOption "Increment selection by scope [treesitter]" "grc";
decrementByNode = mkMappingOption "Decrement selection by node [treesitter]" "grm";
};
fold = mkEnableOption "fold with treesitter";
autotagHtml = mkEnableOption "autoclose and rename html tag";
@ -25,14 +16,14 @@ in {
type = listOf package;
default = [];
example = literalExpression ''
with pkgs.vimPlugins.nvim-treesitter.grammarPlugins; [
with pkgs.vimPlugins.nvim-treesitter.parsers; [
regex
kdl
];
'';
description = ''
List of treesitter grammars to install. For grammars to be installed properly,
you must use grammars from `pkgs.vimPlugins.nvim-treesitter.grammarPlugins`.
you must use grammars from `pkgs.vimPlugins.nvim-treesitter.parsers` or `pkgs.vimPlugins.nvim-treesitter.grammarPlugins`.
You can use `pkgs.vimPlugins.nvim-treesitter.allGrammars` to install all grammars.
For languages already supported by nvf, you may use
@ -56,7 +47,7 @@ in {
internal = true;
readOnly = true;
type = listOf package;
default = with pkgs.vimPlugins.nvim-treesitter.grammarPlugins; [c lua vim vimdoc query];
default = with pkgs.vimPlugins.nvim-treesitter.parsers; [c lua vim vimdoc query];
description = ''
A list of treesitter grammars that will be installed by default
if treesitter has been enabled and {option}`vim.treeesitter.addDefaultGrammars`
@ -73,105 +64,7 @@ in {
'';
};
indent = {
enable = mkEnableOption "indentation with treesitter" // {default = true;};
disable = mkOption {
type = either (listOf str) luaInline;
default = [];
example = literalExpression ''["c" "rust"]'';
description = ''
List of treesitter grammars to disable indentation for.
This option can be either a list, in which case it will be
converted to a Lua table containing grammars to disable
indentation for, or a string containing a **lua function**
that will be read as is.
::: {.warning}
A comma will be added at the end of your function, so you
do not need to add it yourself. Doing so will cause in
syntax errors within your Neovim configuration.
:::
'';
};
};
highlight = {
enable = mkEnableOption "highlighting with treesitter" // {default = true;};
disable = mkOption {
type = either (listOf str) luaInline;
default = [];
example = literalMD ''
```lua
-- Disable slow treesitter highlight for large files
function(lang, buf)
local max_filesize = 1000 * 1024 -- 1MB
local ok, stats = pcall(vim.uv.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
end
end
```
'';
description = ''
List of treesitter grammars to disable highlighting for.
This option can be either a list, in which case it will be
converted to a Lua table containing grammars to disable
highlighting for, or a string containing a **lua function**
that will be read as is.
::: {.warning}
A comma will be added at the end of your function, so you
do not need to add it yourself. Doing so will cause in
syntax errors within your Neovim configuration.
:::
'';
};
additionalVimRegexHighlighting = mkOption {
type = either bool (listOf str);
default = false;
description = ''
Takes either a boolean or a list of languages.
Setting this to true will run `:h syntax` and tree-sitter at the same time.
You may this to `true` if you depend on 'syntax' being enabled (like for
indentation).
::: {.note}
Using this option may slow down your editor, and you may see some duplicate
highlights.
:::
'';
};
};
incrementalSelection = {
enable = mkEnableOption "incremental selection with treesitter" // {default = true;};
disable = mkOption {
type = either (listOf str) luaInline;
default = [];
example = literalExpression ''["c" "rust" ]'';
description = ''
List of treesitter grammars to disable incremental selection
for.
This option can be either a list, in which case it will be
converted to a Lua table containing grammars to disable
indentation for, or a string containing a **lua function**
that will be read as is.
::: {.warning}
A comma will be added at the end of your function, so you
do not need to add it yourself. Doing so will cause in
syntax errors within your Neovim configuration.
:::
'';
};
};
indent = {enable = mkEnableOption "indentation with treesitter" // {default = true;};};
highlight = {enable = mkEnableOption "highlighting with treesitter" // {default = true;};};
};
}