Compare commits

...

15 commits

Author SHA1 Message Date
Ching Pei Yang
f7a08f34ab
Merge 6657f0d8cc into 773186d93d 2024-08-01 20:34:11 +00:00
Ching Pei Yang
6657f0d8cc lib: add lz.n KeySpec 2024-08-01 22:33:51 +02:00
Pei Yang Ching
5b8414a6a6 nvim-tree: use lazy 2024-07-24 13:23:53 +02:00
Pei Yang Ching
ca98d6d2c3 lazy: add setupOpts support 2024-07-24 13:23:35 +02:00
Pei Yang Ching
0638bcb60d fix: broken optPlugins 2024-07-24 12:36:49 +02:00
Pei Yang Ching
c97476bd3e switch to other hacky array-table syntax 2024-07-24 12:30:32 +02:00
Pei Yang Ching
9bf95b70c7 wrap lazy init code in function 2024-07-24 12:30:32 +02:00
Ching Pei Yang
e9fb27ae81 flake: update lz.n 2024-07-24 12:30:32 +02:00
Ching Pei Yang
b1fab22b11 lib: add lznPluginTableType 2024-07-24 12:30:32 +02:00
Ching Pei Yang
3b67decbb1 lib: export lznPluginType 2024-07-24 12:30:32 +02:00
Ching Pei Yang
434c2e233e lz.n: load lz.n 2024-07-24 12:30:32 +02:00
Ching Pei Yang
e839f68a60 lz.n: add basic lazy.plugins option 2024-07-24 12:30:32 +02:00
Pei Yang Ching
efd20adfd9 lib: add basic lz.n plugin spec type 2024-07-24 12:30:32 +02:00
Pei Yang Ching
baf216bb0f add lazy module skeleton 2024-07-24 12:30:32 +02:00
Pei Yang Ching
295b2336c5 flake: add lz.n plugin 2024-07-24 12:30:32 +02:00
10 changed files with 263 additions and 17 deletions

View file

@ -843,6 +843,22 @@
"type": "github" "type": "github"
} }
}, },
"plugin-lz-n": {
"flake": false,
"locked": {
"lastModified": 1719989949,
"narHash": "sha256-oHwmlLgdJJDz5+gs1KLAa2MHQAadM/JYmHGfep9yl28=",
"owner": "nvim-neorocks",
"repo": "lz.n",
"rev": "4c790ba2c3789f580aa019712bbe3112f85e73a0",
"type": "github"
},
"original": {
"owner": "nvim-neorocks",
"repo": "lz.n",
"type": "github"
}
},
"plugin-mind-nvim": { "plugin-mind-nvim": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -1856,6 +1872,7 @@
"plugin-lspkind": "plugin-lspkind", "plugin-lspkind": "plugin-lspkind",
"plugin-lspsaga": "plugin-lspsaga", "plugin-lspsaga": "plugin-lspsaga",
"plugin-lualine": "plugin-lualine", "plugin-lualine": "plugin-lualine",
"plugin-lz-n": "plugin-lz-n",
"plugin-mind-nvim": "plugin-mind-nvim", "plugin-mind-nvim": "plugin-mind-nvim",
"plugin-minimap-vim": "plugin-minimap-vim", "plugin-minimap-vim": "plugin-minimap-vim",
"plugin-modes-nvim": "plugin-modes-nvim", "plugin-modes-nvim": "plugin-modes-nvim",

View file

@ -102,6 +102,12 @@
}; };
## Plugins ## Plugins
# Lazy loading
plugin-lz-n = {
url = "github:nvim-neorocks/lz.n";
flake = false;
};
# LSP plugins # LSP plugins
plugin-nvim-lspconfig = { plugin-nvim-lspconfig = {
url = "github:neovim/nvim-lspconfig"; url = "github:neovim/nvim-lspconfig";

View file

@ -9,7 +9,7 @@
typesCustom = import ./custom.nix {inherit lib;}; typesCustom = import ./custom.nix {inherit lib;};
in { in {
inherit (typesDag) dagOf; inherit (typesDag) dagOf;
inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType; inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType lznPluginType lznPluginTableType;
inherit (typesLanguage) diagnostics mkGrammarOption; inherit (typesLanguage) diagnostics mkGrammarOption;
inherit (typesCustom) anythingConcatLists char; inherit (typesCustom) anythingConcatLists char;
} }

View file

@ -6,8 +6,7 @@
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair; inherit (lib.attrsets) attrNames mapAttrs' filterAttrs nameValuePair;
inherit (lib.strings) hasPrefix removePrefix; inherit (lib.strings) hasPrefix removePrefix;
inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr; inherit (lib.types) submodule either package enum str lines attrsOf anything listOf nullOr oneOf bool;
# Get the names of all flake inputs that start with the given prefix. # Get the names of all flake inputs that start with the given prefix.
fromInputs = { fromInputs = {
inputs, inputs,
@ -51,8 +50,157 @@
}; };
}; };
}; };
luaInline = lib.mkOptionType {
name = "luaInline";
check = x: lib.nvim.lua.isLuaInline x;
};
lznKeysSpec = submodule {
apply = x:
x
// {
"@1" = x.lhs;
"@2" = x.rhs;
};
options = {
desc = mkOption {
description = "Description of the key map";
type = nullOr str;
default = null;
};
noremap = mkOption {
description = "TBD";
type = bool;
default = false;
};
expr = mkOption {
description = "TBD";
type = bool;
default = false;
};
nowait = mkOption {
description = "TBD";
type = bool;
default = false;
};
ft = mkOption {
description = "TBD";
type = nullOr (listOf str);
default = null;
};
lhs = mkOption {
type = str;
description = "Key to bind to";
};
rhs = mkOption {
type = nullOr str;
default = null;
description = "Action to trigger";
};
mode = mkOption {
description = "Modes to bind in";
type = listOf str;
default = ["n"];
};
};
};
lznPluginTableType = attrsOf lznPluginType;
lznPluginType = submodule {
options = {
## Should probably infer from the actual plugin somehow
## In general this is the name passed to packadd, so the dir name of the plugin
# name = mkOption {
# type= str;
# }
# Non-lz.n options
package = mkOption {
type = pluginType;
description = "Plugin package";
};
setupModule = mkOption {
type = nullOr str;
description = "Lua module to run setup function on.";
default = null;
};
setupOpts = mkOption {
type = submodule {freeformType = attrsOf anything;};
description = "Options to pass to the setup function";
default = {};
};
# lz.n options
before = mkOption {
type = nullOr luaInline;
description = "Code to run before plugin is loaded";
default = null;
};
after = mkOption {
type = nullOr luaInline;
description = "Code to run after plugin is loaded";
default = null;
};
event = mkOption {
description = "Lazy-load on event";
default = null;
type = let
event = submodule {
options = {
event = mkOption {
type = nullOr (either str (listOf str));
description = "Exact event name";
example = "BufEnter";
};
pattern = mkOption {
type = nullOr (either str (listOf str));
description = "Event pattern";
example = "BufEnter *.lua";
};
};
};
in
nullOr (oneOf [str (listOf str) event]);
};
cmd = mkOption {
description = "Lazy-load on command";
default = null;
type = nullOr (either str (listOf str));
};
ft = mkOption {
description = "Lazy-load on filetype";
default = null;
type = nullOr (either str (listOf str));
};
keys = mkOption {
description = "Lazy-load on key mapping";
default = null;
type = nullOr (oneOf [str (listOf str) lznKeysSpec]); # TODO: support lz.n.KeysSpec
};
# TODO: enabled, beforeAll, colorscheme, priority, load
};
};
in { in {
inherit extraPluginType fromInputs pluginType; inherit extraPluginType fromInputs pluginType luaInline lznPluginType lznPluginTableType;
pluginsOpt = { pluginsOpt = {
description, description,
@ -64,11 +212,6 @@ in {
type = pluginsType; type = pluginsType;
}; };
luaInline = lib.mkOptionType {
name = "luaInline";
check = x: lib.nvim.lua.isLuaInline x;
};
/* /*
opts is a attrset of options, example: opts is a attrset of options, example:
``` ```

View file

@ -88,10 +88,7 @@ inputs: {
# built (or "normalized") plugins that are modified # built (or "normalized") plugins that are modified
builtStartPlugins = buildConfigPlugins vimOptions.startPlugins; builtStartPlugins = buildConfigPlugins vimOptions.startPlugins;
builtOptPlugins = map (package: { builtOptPlugins = map (package: package // {optional = true;}) (buildConfigPlugins vimOptions.optPlugins);
plugin = package;
optional = true;
}) (buildConfigPlugins vimOptions.optPlugins);
# additional Lua and Python3 packages, mapped to their respective functions # additional Lua and Python3 packages, mapped to their respective functions
# to conform to the format makeNeovimConfig expects. end user should # to conform to the format makeNeovimConfig expects. end user should

View file

@ -50,6 +50,7 @@
wrapper = map (p: ./wrapper + "/${p}") [ wrapper = map (p: ./wrapper + "/${p}") [
"build" "build"
"rc" "rc"
"lazy"
"warnings" "warnings"
]; ];

View file

@ -16,8 +16,6 @@
inherit (self.options.vim.filetree.nvimTree) mappings; inherit (self.options.vim.filetree.nvimTree) mappings;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = ["nvim-tree-lua"];
vim.maps.normal = mkMerge [ vim.maps.normal = mkMerge [
(mkBinding cfg.mappings.toggle ":NvimTreeToggle<cr>" mappings.toggle.description) (mkBinding cfg.mappings.toggle ":NvimTreeToggle<cr>" mappings.toggle.description)
(mkBinding cfg.mappings.refresh ":NvimTreeRefresh<cr>" mappings.refresh.description) (mkBinding cfg.mappings.refresh ":NvimTreeRefresh<cr>" mappings.refresh.description)
@ -29,6 +27,17 @@ in {
"<leader>t" = "+NvimTree"; "<leader>t" = "+NvimTree";
}; };
vim.lazy = {
plugins = {
nvim-tree-lua = {
package = "nvim-tree-lua";
setupModule = "nvim-tree";
inherit (cfg) setupOpts;
cmd = ["NvimTreeClipboard" "NvimTreeClose" "NvimTreeCollapse" "NvimTreeCollapseKeepBuffers" "NvimTreeFindFile" "NvimTreeFindFileToggle" "NvimTreeFocus" "NvimTreeHiTest" "NvimTreeOpen" "NvimTreeRefresh" "NvimTreeResize" "NvimTreeToggle"];
};
};
};
vim.pluginRC.nvimtreelua = entryAnywhere '' vim.pluginRC.nvimtreelua = entryAnywhere ''
${ ${
optionalString cfg.setupOpts.disable_netrw '' optionalString cfg.setupOpts.disable_netrw ''
@ -38,8 +47,6 @@ in {
'' ''
} }
require'nvim-tree'.setup(${toLuaObject cfg.setupOpts})
${ ${
optionalString cfg.openOnSetup '' optionalString cfg.openOnSetup ''
-- autostart behaviour -- autostart behaviour

View file

@ -0,0 +1,40 @@
{
lib,
config,
...
}: let
inherit (builtins) toJSON;
inherit (lib.modules) mkIf;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.generators) mkLuaInline;
inherit (lib.strings) optionalString;
inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.lazy;
toLuaLznSpec = name: spec:
(removeAttrs spec ["package" "setupModule" "setupOpts"])
// {
"@1" = name;
after = mkLuaInline ''
function()
${
optionalString (spec.setupModule != null)
"require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})"
}
${optionalString (spec.after != null) spec.after}
end
'';
};
lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins;
in {
config.vim = mkIf cfg.enable {
startPlugins = ["lz-n"];
optPlugins = mapAttrsToList (_: plugin: plugin.package) cfg.plugins;
luaConfigRC.lzn-load = entryAnywhere ''
require('lz.n').load(${toLuaObject lznSpecs})
'';
};
}

View file

@ -0,0 +1,6 @@
_: {
imports = [
./lazy.nix
./config.nix
];
}

View file

@ -0,0 +1,29 @@
{lib, ...}: let
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) enum;
inherit (lib.nvim.types) lznPluginTableType;
in {
options.vim.lazy = {
enable = mkEnableOption "plugin lazy-loading" // {default = true;};
loader = mkOption {
description = "Lazy loader to use";
type = enum ["lz.n"];
default = "lz.n";
};
plugins = mkOption {
default = {};
type = lznPluginTableType;
description = "list of plugins to lazy load";
example = ''
{
toggleterm-nvim = {
package = "toggleterm-nvim";
after = lib.generators.mkLuaInline "function() require('toggleterm').setup{} end";
cmd = ["ToggleTerm"];
};
}
'';
};
};
}