treesitter: ensure_installed to none if using nix

This is a temporary workaround for an upstream bug which causes
nvim-treesitter to complain about a read-only installation directory
This commit is contained in:
Pedro Alves 2022-09-12 13:04:24 +01:00
parent 88fb867da5
commit bd6f978d51

View file

@ -15,43 +15,45 @@ in
description = "Install grammars with Nix (beta)"; description = "Install grammars with Nix (beta)";
}; };
ensureInstalled = mkOption { ensureInstalled = mkOption {
type = with types; oneOf [ (enum ["all"]) (listOf str) ]; type = with types; oneOf [ (enum [ "all" ]) (listOf str) ];
default = "all"; default = "all";
description = "Either \"all\" or a list of languages"; description = "Either \"all\" or a list of languages";
}; };
ignoreInstall = mkOption { ignoreInstall = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = []; default = [ ];
description = "List of parsers to ignore installing (for \"all\")"; description = "List of parsers to ignore installing (for \"all\")";
}; };
disabledLanguages = mkOption { disabledLanguages = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = []; default = [ ];
description = "A list of languages to disable"; description = "A list of languages to disable";
}; };
customCaptures = mkOption { customCaptures = mkOption {
type = types.attrsOf types.str; type = types.attrsOf types.str;
default = {}; default = { };
description = "Custom capture group highlighting"; description = "Custom capture group highlighting";
}; };
incrementalSelection = let incrementalSelection =
keymap = default: mkOption { let
type = types.str; keymap = default: mkOption {
inherit default; 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";
};
}; };
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";
};
};
indent = mkEnableOption "Enable tree-sitter based indentation"; indent = mkEnableOption "Enable tree-sitter based indentation";
@ -59,48 +61,52 @@ in
}; };
}; };
config = let config =
tsOptions = { let
highlight = { tsOptions = {
enable = cfg.enable; highlight = {
disable = if (cfg.disabledLanguages != []) then cfg.disabledLanguages else null; enable = cfg.enable;
disable = if (cfg.disabledLanguages != [ ]) then cfg.disabledLanguages else null;
custom_captures = if (cfg.customCaptures != {}) then cfg.customCaptures else null; custom_captures = if (cfg.customCaptures != { }) then cfg.customCaptures else null;
};
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;
indent = if cfg.indent then { incremental_selection =
enable = true; if cfg.incrementalSelection.enable then {
} else null; 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;
ensure_installed = cfg.ensureInstalled; indent =
ignore_install = cfg.ignoreInstall; if cfg.indent then {
}; enable = true;
in mkIf cfg.enable { } else null;
programs.nixvim = {
extraConfigLua = ''
require('nvim-treesitter.configs').setup(${helpers.toLuaObject tsOptions})
'';
extraPlugins = with pkgs; if cfg.nixGrammars then ensure_installed = if cfg.nixGrammars then [ ] else cfg.ensureInstalled;
[ (vimPlugins.nvim-treesitter.withPlugins(_: tree-sitter.allGrammars)) ] ignore_install = cfg.ignoreInstall;
else [ vimPlugins.nvim-treesitter ]; };
extraPackages = [ pkgs.tree-sitter pkgs.nodejs ]; in
mkIf cfg.enable {
programs.nixvim = {
extraConfigLua = ''
require('nvim-treesitter.configs').setup(${helpers.toLuaObject tsOptions})
'';
options = mkIf cfg.folding { extraPlugins = with pkgs; if cfg.nixGrammars then
foldmethod = "expr"; [ (vimPlugins.nvim-treesitter.withPlugins (_: tree-sitter.allGrammars)) ]
foldexpr = "nvim_treesitter#foldexpr()"; else [ vimPlugins.nvim-treesitter ];
extraPackages = [ pkgs.tree-sitter pkgs.nodejs ];
options = mkIf cfg.folding {
foldmethod = "expr";
foldexpr = "nvim_treesitter#foldexpr()";
};
}; };
}; };
};
} }