1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
{
pkgs,
lib,
...
}: let
inherit (lib.options) mkOption mkEnableOption literalExpression literalMD;
inherit (lib.types) listOf nullOr package bool str lines enum submodule oneOf attrsOf;
queriesType = submodule {
options = {
type = mkOption {
type = enum ["injections" "highlights" "folds" "locals" "indents"];
description = "The kind of query to register.";
};
loadtype = mkOption {
type = enum ["overwrite" "extends"];
description = "Define how this query should be loaded";
};
filetypes = mkOption {
type = listOf str;
default = [];
description = "The filetypes for which the query should be registered.";
};
query = mkOption {
type = lines;
description = "The queries scm script.";
# Syntactica doesnt support `query` so we patch it with the closest it does,
# which is `haskell` :bwaa:
example = literalMD ''
```haskell
((apply_expression
function: (variable_expression
name: (identifier) @_func
(#eq? @_func "mkLuaInline"))
argument: (indented_string_expression
(string_fragment) @injection.content)
(#set! injection.language "lua")
(#set! injection.combined)))
```
'';
};
};
};
in {
options.vim.treesitter = {
enable = mkEnableOption "treesitter, also enabled automatically through language options";
fold = mkEnableOption "fold with treesitter";
autotagHtml = mkEnableOption "autoclose and rename html tag";
vendorCLI = mkEnableOption ''
bundling the treesitter CLI.
This is required to compile and install custom parsers outside the nix configuration.
'';
grammars = mkOption {
type = listOf (nullOr package);
default = [];
example = literalExpression ''
with pkgs.vimPlugins.nvim-treesitter.grammarPlugins; [
regex
kdl
];
'';
description = ''
List of treesitter grammars to install. For grammars to be installed properly,
you must use grammars from one of those:
- `pkgs.vimPlugins.nvim-treesitter.parsers`
- `pkgs.vimPlugins.nvim-treesitter.grammarPlugins`
- `pkgs.tree-sitter-grammars` (mostly untested)
You can use `pkgs.vimPlugins.nvim-treesitter.allGrammars` to install all grammars shipped with `nvim-treesitter`.
For languages already supported by nvf, you may use
{option}`vim.language.<lang>.treesitter` options, which will automatically add
the required grammars to this.
'';
};
addDefaultGrammars = mkOption {
type = bool;
default = true;
description = ''
Whether to add the default grammars to the list of grammars
to install.
This option is only relevant if treesitter has been enabled.
'';
};
defaultGrammars = mkOption {
internal = true;
readOnly = true;
type = listOf package;
default = with pkgs.vimPlugins.nvim-treesitter.grammarPlugins; [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`
has been set to true.
::: {.note}
Regardless of which language module options you enable, Neovim
depends on those grammars to be enabled while treesitter is enabled.
This list cannot be modified, but if you would like to bring your own
parsers instead of those provided here, you can set `addDefaultGrammars`
to false
:::
'';
};
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;};};
queries = mkOption {
type = listOf queriesType;
default = [];
description = "A list of Neovim treesitter queries to be registered.";
example = [
{
type = "injections";
filetypes = ["nix"];
loadtype = "extends";
query = ''
(apply_expression
function: (variable_expression
name: (identifier) @_func
(#eq? @_func "mkLuaInline"))
argument: (indented_string_expression
(string_fragment) @injection.content)
(#set! injection.language "lua")
(#set! injection.combined))
'';
}
];
};
filetypeMappings = mkOption {
type = attrsOf (listOf str);
default = {};
example = {
"sh" = ["ash" "dash"];
};
description = ''
For each parser, registers a list of alternative filetypes.
For more information see `:h vim.treesitter.language.register()`.
See treesitter builtin mappings here: <https://github.com/nvim-treesitter/nvim-treesitter/blob/main/plugin/filetypes.lua>
'';
};
};
}
|