2020-12-31 18:15:19 +00:00
|
|
|
{ pkgs, lib, config, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
2021-02-01 16:29:30 +00:00
|
|
|
cfg = config.programs.nixvim.plugins.treesitter;
|
2021-02-01 16:21:42 +00:00
|
|
|
helpers = import ../helpers.nix { inherit lib; };
|
2020-12-31 18:15:19 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
programs.nixvim.plugins.treesitter = {
|
2021-02-01 16:21:42 +00:00
|
|
|
enable = mkEnableOption "Enable tree-sitter syntax highlighting";
|
|
|
|
|
|
|
|
ensureInstalled = mkOption {
|
|
|
|
type = with types; oneOf [ (enum [ "all" "maintained" ]) (listOf str) ];
|
|
|
|
default = "maintained";
|
|
|
|
description = "Either \"all\", \"maintained\" or a list of languages";
|
|
|
|
};
|
|
|
|
|
|
|
|
disabledLanguages = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = "A list of languages to disable";
|
|
|
|
};
|
|
|
|
|
|
|
|
customCaptures = mkOption {
|
|
|
|
type = types.attrsOf types.str;
|
|
|
|
default = {};
|
|
|
|
description = "Custom capture group highlighting";
|
|
|
|
};
|
|
|
|
|
|
|
|
incrementalSelection = let
|
|
|
|
keymap = default: mkOption {
|
|
|
|
type = types.str;
|
2021-02-01 16:40:07 +00:00
|
|
|
inherit default;
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
enable = mkEnableOption "Incremental selection based on the named nodes from the grammar";
|
|
|
|
keymaps = {
|
|
|
|
initSelection = keymap "gnn";
|
|
|
|
nodeIncremental = keymap "grn";
|
|
|
|
scopeIncremental = keymap "grc";
|
|
|
|
nodeDecremental = keymap "grm";
|
2021-02-01 16:21:42 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
indent = mkEnableOption "Enable tree-sitter based indentation";
|
|
|
|
|
|
|
|
folding = mkEnableOption "Enable tree-sitter based folding";
|
2020-12-31 18:15:19 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-02-01 16:21:42 +00:00
|
|
|
config = let
|
|
|
|
tsOptions = {
|
|
|
|
highlight = {
|
|
|
|
enable = cfg.enable;
|
2021-02-10 21:01:07 +00:00
|
|
|
disable = if (cfg.disabledLanguages != []) then cfg.disabledLanguages else null;
|
2021-02-01 16:21:42 +00:00
|
|
|
|
2021-02-10 21:01:07 +00:00
|
|
|
custom_captures = if (cfg.customCaptures != {}) then cfg.customCaptures else null;
|
2021-02-01 16:21:42 +00:00
|
|
|
};
|
|
|
|
|
2021-02-10 21:01:07 +00:00
|
|
|
incremental_selection = if cfg.incrementalSelection.enable then {
|
|
|
|
enable = true;
|
|
|
|
keymaps = {
|
|
|
|
init_selection = cfg.incrementalSelection.keymaps.initSelection;
|
|
|
|
node_incremental = cfg.incrementalSelection.keymaps.nodeIncremental;
|
|
|
|
scope_incremental = cfg.incrementalSelection.keymaps.scopeIncremental;
|
|
|
|
node_decremental = cfg.incrementalSelection.keymaps.nodeDecremental;
|
|
|
|
};
|
|
|
|
} else null;
|
2021-02-01 16:21:42 +00:00
|
|
|
|
2021-02-10 21:01:07 +00:00
|
|
|
indent = if cfg.indent then {
|
2021-02-01 16:21:42 +00:00
|
|
|
enable = true;
|
2021-02-10 21:01:07 +00:00
|
|
|
} else null;
|
2021-02-01 16:21:42 +00:00
|
|
|
|
|
|
|
ensure_installed = cfg.ensureInstalled;
|
|
|
|
};
|
|
|
|
in mkIf cfg.enable {
|
2020-12-31 18:15:19 +00:00
|
|
|
programs.nixvim = {
|
|
|
|
extraPlugins = [ pkgs.vimPlugins.nvim-treesitter ];
|
2021-02-01 16:21:42 +00:00
|
|
|
|
|
|
|
extraConfigLua = ''
|
|
|
|
require('nvim-treesitter.configs').setup(${helpers.toLuaObject tsOptions})
|
|
|
|
'';
|
|
|
|
|
|
|
|
options = mkIf cfg.folding {
|
|
|
|
foldmethod = "expr";
|
|
|
|
foldexpr = "nvim_treesitter#foldexpr()";
|
|
|
|
};
|
2020-12-31 18:15:19 +00:00
|
|
|
};
|
2021-02-01 16:28:06 +00:00
|
|
|
};
|
2020-12-31 18:15:19 +00:00
|
|
|
}
|