nix-community.nixvim/plugins/languages/treesitter.nix

146 lines
4.5 KiB
Nix
Raw Normal View History

{ pkgs, lib, config, ... }:
with lib;
let
cfg = config.plugins.treesitter;
2021-02-01 16:21:42 +00:00
helpers = import ../helpers.nix { inherit lib; };
in
{
options = {
plugins.treesitter = {
2021-02-01 16:21:42 +00:00
enable = mkEnableOption "Enable tree-sitter syntax highlighting";
general: add package options (#127) * barbar: package option * Base16: package option * gruvbox: package option * nord: package option * one: package option * onedark: package option * tokyonight: package option * nvim-cmp: package option * coq: package option * lspkind: package option * helpers: added package option to mkPlugin * fugitive: package option * gitgutter: package option * gitsigns: package option * neogit: package option * ledger: package option * nix: package option * plantuml-syntax: package option * treesitter-context: package option + formatting * treesitter-refactor: package option + formatting * treesitter: package option * zig: package option * null-ls: package option * null-ls/servers: package option * lsp-lines: package option * lspsaga: package option * trouble: package option * luasnip: added description for package option * airline: package option * lightline: package option * lualine: package option * telescope: package option * telescope/frecency: package option * telescope/fzf-native: package option * telescope/media-files: package option * comment-nvim: package option * vim-commentary: package option * dashboard: package option * easyescape: package option * emmet: package option * endwise: package option * floaterm: package option * goyo: package option * intellitab: package option * mark-radar: package option * notify: package option * nvim-autopairs: package option * nvim-tree: package option * project-nvim: package option * specs: package option * startify: package option * surround: package option * undotree: package option
2023-01-19 10:45:15 +00:00
package = mkOption {
type = types.package;
default = pkgs.vimPlugins.nvim-treesitter;
description = "Plugin to use for nvim-treesitter. If using nixGrammars, it should include a `withPlugins` function";
};
nixGrammars = mkOption {
type = types.bool;
default = true;
description = "Install grammars with Nix";
};
2021-02-01 16:21:42 +00:00
ensureInstalled = mkOption {
type = with types; oneOf [ (enum [ "all" ]) (listOf str) ];
default = "all";
description = "Either \"all\" or a list of languages";
};
parserInstallDir = mkOption {
type = types.nullOr types.str;
default =
if cfg.nixGrammars
then null
else "$XDG_DATA_HOME/nvim/treesitter"
;
description = ''
Location of the parsers to be installed by the plugin (only needed when nixGrammars is disabled).
This default might not work on your own install, please make sure that $XDG_DATA_HOME is set if you want to use the default. Otherwise, change it to something that will work for you!
'';
};
ignoreInstall = mkOption {
type = types.listOf types.str;
default = [ ];
description = "List of parsers to ignore installing (for \"all\")";
2021-02-01 16:21:42 +00:00
};
disabledLanguages = mkOption {
type = types.listOf types.str;
default = [ ];
2021-02-01 16:21:42 +00:00
description = "A list of languages to disable";
};
customCaptures = mkOption {
type = types.attrsOf types.str;
default = { };
2021-02-01 16:21:42 +00:00
description = "Custom capture group highlighting";
};
incrementalSelection =
let
keymap = default: mkOption {
type = types.str;
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:40:07 +00:00
};
2021-02-01 16:21:42 +00:00
indent = mkEnableOption "Enable tree-sitter based indentation";
folding = mkEnableOption "Enable tree-sitter based folding";
2022-12-01 14:05:35 +00:00
2022-12-01 14:07:08 +00:00
grammarPackages = mkOption {
type = with types; listOf package;
default = pkgs.tree-sitter.allGrammars;
description = "Grammar packages to install";
};
moduleConfig = mkOption {
type = types.attrsOf types.anything;
default = { };
description = "This is the configuration for extra modules. It should not be used directly";
};
2022-12-01 14:05:35 +00:00
};
};
config =
let
tsOptions = {
highlight = {
enable = cfg.enable;
disable = if (cfg.disabledLanguages != [ ]) then cfg.disabledLanguages else null;
2021-02-01 16:21:42 +00:00
custom_captures = if (cfg.customCaptures != { }) then cfg.customCaptures else null;
2021-02-10 21:01:07 +00:00
};
2021-02-01 16:21:42 +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
indent =
if cfg.indent then {
enable = true;
} else null;
2021-12-11 15:09:11 +00:00
ensure_installed = if cfg.nixGrammars then [ ] else cfg.ensureInstalled;
ignore_install = cfg.ignoreInstall;
parser_install_dir = cfg.parserInstallDir;
} // cfg.moduleConfig;
in
mkIf cfg.enable {
extraConfigLua = (optionalString (cfg.parserInstallDir != null) ''
vim.opt.runtimepath:append("${cfg.parserInstallDir}")
'') + ''
require('nvim-treesitter.configs').setup(${helpers.toLuaObject tsOptions})
'';
extraPlugins = with pkgs; if cfg.nixGrammars then
general: add package options (#127) * barbar: package option * Base16: package option * gruvbox: package option * nord: package option * one: package option * onedark: package option * tokyonight: package option * nvim-cmp: package option * coq: package option * lspkind: package option * helpers: added package option to mkPlugin * fugitive: package option * gitgutter: package option * gitsigns: package option * neogit: package option * ledger: package option * nix: package option * plantuml-syntax: package option * treesitter-context: package option + formatting * treesitter-refactor: package option + formatting * treesitter: package option * zig: package option * null-ls: package option * null-ls/servers: package option * lsp-lines: package option * lspsaga: package option * trouble: package option * luasnip: added description for package option * airline: package option * lightline: package option * lualine: package option * telescope: package option * telescope/frecency: package option * telescope/fzf-native: package option * telescope/media-files: package option * comment-nvim: package option * vim-commentary: package option * dashboard: package option * easyescape: package option * emmet: package option * endwise: package option * floaterm: package option * goyo: package option * intellitab: package option * mark-radar: package option * notify: package option * nvim-autopairs: package option * nvim-tree: package option * project-nvim: package option * specs: package option * startify: package option * surround: package option * undotree: package option
2023-01-19 10:45:15 +00:00
[ (cfg.package.withPlugins (_: cfg.grammarPackages)) ]
else [ cfg.package ];
extraPackages = [ pkgs.tree-sitter pkgs.nodejs ];
options = mkIf cfg.folding {
foldmethod = "expr";
foldexpr = "nvim_treesitter#foldexpr()";
2021-02-01 16:21:42 +00:00
};
};
}