add nvim-tree-lua module

This commit is contained in:
Dmitriy Pleshevskiy 2024-04-17 19:35:34 +03:00
parent d3e0b8c0d9
commit 3eb6c9b8d8
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
4 changed files with 132 additions and 74 deletions

View file

@ -197,11 +197,11 @@
}, },
"nix2lua": { "nix2lua": {
"locked": { "locked": {
"lastModified": 1709128456, "lastModified": 1713368896,
"narHash": "sha256-tRduS+XFI6VceWPQzjkuvlyn/Oe5NsQUS/wyEC69dvk=", "narHash": "sha256-ivvxVxSpuri8rYP3FVdcxSRrabejAz6iAQvXqdzEGLc=",
"ref": "refs/heads/main", "ref": "refs/heads/main",
"rev": "f152767145e61fea96eddb1b550ab3f25701e0ad", "rev": "98eaf7a9c2a7e608387debeca8f403885fbec0e4",
"revCount": 18, "revCount": 29,
"type": "git", "type": "git",
"url": "https://git.pleshevski.ru/mynix/nix2lua" "url": "https://git.pleshevski.ru/mynix/nix2lua"
}, },

View file

@ -243,32 +243,42 @@
minimalNeovim = mkNeovim pkgs; minimalNeovim = mkNeovim pkgs;
recommendedNeovim = (minimalNeovim.override { recommendedNeovim = minimalNeovim.override {
enableDevIcons = true; modules = {
enableTabby = false; nvim-tree-lua = {
configs = {
renderer = {
group_empty = true;
full_name = true;
};
plugins = with minimalNeovim.nix2lua; {
nvimTree.settings = {
renderer = {
group_empty = true;
full_name = true;
};
};
lualine.settings = {
options.ignore_focus = [ "NvimTree" ];
sections = {
lualine_a = [
[ "filename" (mkNamedField "path" 1) ]
];
lualine_b = [ "branch" "diff" "diagnostics" ];
lualine_c = [ "lsp_progress" ];
lualine_x = [ "filesize" "filetype" ];
lualine_y = [ "progress" ];
lualine_z = [ "location" "mode" ];
}; };
keymaps = [
{ mode = "n"; bind = "<leader>nt"; command = "<CMD>NvimTreeToggle<CR>"; }
{ mode = "n"; bind = "<leader>nf"; command = "<CMD>NvimTreeFindFile<CR>"; }
];
}; };
}; };
});
plugins = with minimalNeovim.nix2lua; {
lualine-nvim = pipe [
(require "lualine")
(call "setup" [{
options.ignore_focus = [ "NvimTree" ];
sections = {
lualine_a = [
[ "filename" (namedField "path" 1) ]
];
lualine_b = [ "branch" "diff" "diagnostics" ];
lualine_c = [ "lsp_progress" ];
lualine_x = [ "filesize" "filetype" ];
lualine_y = [ "progress" ];
lualine_z = [ "location" "mode" ];
};
}])
];
};
};
fullNeovim = recommendedNeovim.override { fullNeovim = recommendedNeovim.override {
plugins = recommendedNeovim.plugins // (with minimalNeovim.nix2lua; { plugins = recommendedNeovim.plugins // (with minimalNeovim.nix2lua; {
@ -305,10 +315,11 @@
}; };
packages = { packages = {
default = recommendedNeovim; # default = recommendedNeovim;
recommended = recommendedNeovim; # full = fullNeovim;
full = fullNeovim;
minimal = minimalNeovim; minimal = minimalNeovim;
recommended = recommendedNeovim;
}; };
in in
{ {

55
modules/nvim-tree-lua.nix Normal file
View file

@ -0,0 +1,55 @@
{ nix2lua }:
{ configs ? { }
, keymaps ? [
{ mode = "n"; bind = "<leader>nt"; command = "<CMD>NvimTreeToggle<CR>"; }
{ mode = "n"; bind = "<leader>nf"; command = "<CMD>NvimTreeFindFile<CR>"; }
]
}:
with nix2lua.lib;
let
vimKeymapSet = { mode, bind, command }: call "vim.keymap.set" [ mode bind command ];
isEmptyVar = name: eq "" (var name);
in
{
nvim-tree-lua = (
[
(pipe [ (require "nvim-tree") (call "setup" [ configs ]) ])
(local (func "open_nvim_tree" [ "data" ] [
# buffer is a [No Name]
(local (set "isNoNameBuffer"
(and
(isEmptyVar "data.file")
(isEmptyVar "vim.bo[data.buf].buftype")
)
))
# buffer is a directory
(local (set "isDirectory"
(eq 1 (var "vim.fn.isdirectory(data.file)"))
))
(if' (not (and (var "isNoNameBuffer") (var "isDirectory"))) [
return_void
])
# change to the directory
(if' (var "isDirectory") [
(call "vim.cmd.cd" [ (var "data.file") ])
])
# open the tree
(pipe [ (require "nvim-tree.api") (call "tree.open" [ ]) ])
]))
(call "vim.api.nvim_create_autocmd" [
[ "VimEnter" ]
{ callback = var "open_nvim_tree"; }
])
]
++ (map vimKeymapSet keymaps)
);
}

View file

@ -1,24 +1,19 @@
{ enableDevIcons ? false { viAlias ? false
, enableTabby ? false
, enableOrgMode ? false
, viAlias ? false
, vimAlias ? false , vimAlias ? false
, extraConfig ? "" , extraConfig ? ""
, extraLuaConfig ? "" , extraLuaConfig ? ""
, extraPlugins ? [ ]
, theme ? { }
, plugins ? { }
, wrapNeovim , wrapNeovim
, neovim-unwrapped , neovim-unwrapped
, tree-sitter , tree-sitter
, neovimPlugins , neovimPlugins
, lib , lib
, nix2lua , nix2lua
, substituteAll , plugins ? { }
, callPackage , modules ? { }
, ... , ...
}: }:
let let
plugins' = plugins; plugins' = plugins;
@ -33,48 +28,45 @@ let
in in
let let
plugins = mergeAttrs plugins'; plugins = mergeAttrs plugins';
inherit (builtins) catAttrs readFile;
extLib = import ./lib.nix { inherit lib substituteAll; } // { importModule = moduleName: import (./modules + "/${moduleName}.nix") { inherit nix2lua; };
inherit (nix2lua.lib) toLua LuaNil;
}; allModules = mergeAttrs (lib.mapAttrsToList importModule modules);
pluginsWithModules = mergeAttrs [ allModules plugins ];
pluginParams = neovimPlugins // { /*
inherit tree-sitter plugins enableDevIcons enableTabby enableOrgMode; Type: getPluginByName :: string -> derivation
themeCfg = theme; */
lib = extLib; getPluginByName = lib.flip lib.getAttr neovimPlugins;
}; allPlugins = map getPluginByName (lib.attrNames pluginsWithModules);
callPlugin = plugin: callPackage plugin pluginParams; /*
callPlugins = list: map callPlugin list; Type: mkPluginLuaConfig :: string -> a -> string
*/
mkPluginLuaConfig = name: cfg:
with nix2lua.lib;
"-- Plugin: ${builtins.trace "Plugin: ${name}" name}\n"
+ (if lib.isString cfg then cfg
else if lib.isAttrs cfg then toLua cfg
else if lib.isList cfg then toLua (concatLines cfg)
else abort "[neovim] mkPluginLuaConfig: unsupported type");
pluginLuaConfigs = lib.mapAttrsToList mkPluginLuaConfig pluginsWithModules;
pluginsSettings = callPlugins [ basicLuaConfigs = map builtins.readFile [ ./config/basic.lua ];
./plugins/config
./plugins/syntax
./plugins/git
./plugins/explorer
./plugins/theme
./plugins/lsp
./plugins/formatter
./plugins/ux
];
basePlugins = [ neovimPlugins.plenary-nvim ]; allLuaConfigs = basicLuaConfigs ++ pluginLuaConfigs;
customPlugins = catAttrs "plugins" pluginsSettings;
allPlugins = basePlugins ++ customPlugins ++ extraPlugins;
basicConfigs = map readFile [ ./config/basic.lua ]; /*
pluginConfigs = catAttrs "luaConfig" pluginsSettings; Type: mkLuaHeredoc :: string -> string
allConfigs = basicConfigs ++ pluginConfigs ++ [ extraLuaConfig ]; */
mkLuaHeredoc = content: lib.concatLines [ "lua << EOF" content "EOF" ];
mkLuaHeredoc = content: '' /*
lua << EOF Type: mkLuaRc :: [string] -> string
${content} */
EOF mkLuaRc = list: lib.concatLines (map mkLuaHeredoc list);
'';
mkLuaRc = lib.concatMapStrings mkLuaHeredoc;
in in
(wrapNeovim neovim-unwrapped { (wrapNeovim neovim-unwrapped {
inherit viAlias; inherit viAlias;
@ -85,13 +77,13 @@ in
withRuby = false; withRuby = false;
configure = { configure = {
customRC = extraConfig + mkLuaRc allConfigs; customRC = extraConfig + mkLuaRc allLuaConfigs;
packages.myVimPackages = { start = allPlugins; }; packages.myVimPackages = { start = allPlugins; };
}; };
}).overrideAttrs (oldAttrs: { }).overrideAttrs (oldAttrs: {
passthru = oldAttrs.passthru // { passthru = oldAttrs.passthru // {
nix2lua = nix2lua.lib; nix2lua = nix2lua.lib;
inherit plugins allConfigs; inherit plugins;
}; };
}) })