nixeovim/modules/plugins/navigation/nvim-tree.nix

71 lines
1.7 KiB
Nix
Raw Normal View History

2024-04-27 02:29:05 +03:00
{ config, lib, pkgs, ... }:
let cfg = config.plugins.navigation.nvim-tree; in
{
options.plugins.navigation.nvim-tree = with lib; {
2024-04-27 02:29:05 +03:00
enable = mkEnableOption "nvim-tree";
package = mkPackageOption pkgs.vimPlugins "nvim-tree-lua" { };
settings = mkOption {
type = types.attrs;
2024-04-27 02:29:05 +03:00
default = { };
description = ''
`:help nvim-tree-setup`
'';
};
disableNetrw = mkOption {
type = types.bool;
default = true;
description = ''
Disabling netrw is strongly advised.
`:help nvim-tree-netrw`
'';
2024-04-27 02:29:05 +03:00
};
keymap = {
withDefault = mkOption {
type = types.bool;
default = true;
description = "attach default mappings";
};
set = mkOption {
type = with types; listOf keymap;
default = [ ];
};
};
2024-04-27 02:29:05 +03:00
};
2024-04-27 02:29:05 +03:00
config = lib.mkIf cfg.enable {
fn.nvim-tree-lua-on-attach = lib.mkIf (cfg.keymap.set != [ ]) {
args = [ "bufnr" ];
content = { bufnr }: {
extra = with lib.nix2lua; lib.mkIf cfg.keymap.withDefault pipe [
(require "nvim-tree.api")
(var "config")
(var "mappings")
(call "default_on_attach" bufnr)
];
vim.keymap.set = map (attrs: attrs // { buffer = bufnr; }) cfg.keymap.set;
};
};
2024-04-27 02:29:05 +03:00
plugin.nvim-tree-lua = {
name = "nvim-tree";
package = cfg.package;
setupSettings =
cfg.settings
// lib.optionalAttrs (cfg.keymap.set != [ ]) {
on_attach = config.fn.nvim-tree-lua-on-attach.lambda;
};
2024-04-27 02:29:05 +03:00
};
vim.g = lib.mkIf cfg.disableNetrw {
loaded_netrw = 1;
loaded_netrwPlugin = 1;
};
2024-04-27 02:29:05 +03:00
};
}