-
Notifications
You must be signed in to change notification settings - Fork 51
/
treesitter.nix
64 lines (56 loc) · 1.66 KB
/
treesitter.nix
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
{ pkgs
, config
, lib
, ...
}:
with lib;
with builtins; let
cfg = config.vim.treesitter;
usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp";
in
{
options.vim.treesitter = {
enable = mkEnableOption "treesitter, also enabled automatically through language options";
fold = mkEnableOption "fold with treesitter";
grammars = mkOption {
type = with types; listOf package;
default = [ ];
description = ''
List of treesitter grammars to install. For supported languages
use the `vim.languages.<language>.treesitter.enable` option
'';
};
};
config = mkIf cfg.enable {
vim.startPlugins =
[ "nvim-treesitter" ]
++ optional usingNvimCmp "cmp-treesitter";
vim.autocomplete.sources = { "treesitter" = "[Treesitter]"; };
# For some reason treesitter highlighting does not work on start if this is set before syntax on
vim.configRC.treesitter-fold = mkIf cfg.fold (nvim.dag.entryBefore [ "basic" ] ''
set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr()
set nofoldenable
'');
vim.luaConfigRC.treesitter = nvim.dag.entryAnywhere /* lua */ ''
require'nvim-treesitter.configs'.setup {
highlight = {
enable = true,
disable = {},
},
auto_install = false,
ignore_install = {"all"},
ensure_installed = {},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "gnn",
node_incremental = "grn",
scope_incremental = "grc",
node_decremental = "grm",
},
}
}
'';
};
}