mirror of
https://github.com/NotAShelf/nvf.git
synced 2024-11-25 22:56:46 +00:00
21fcace3ed
* flake: add lz.n and lzn-auto-require * lazy: init module * lzn-auto-require: add init lua code * wrapper: fix opt plugin format * lib.binds: add lz.n variant of bind functions * telescope: lazy load * nvim-tree: lazy load * dapui: lazy load * trouble: lazy load * toggleterm: lazy load * cheatsheet: lazy load * diffview: lazy load * icon-picker: lazy load * leap: lazy load * fidget: lazy load * docs: add section on lazy plugins * lazy: support lazy.enable=false * comment-nvim: lazy load * surround-nvim: lazy load * neo-tree: lazy load * fixup! lazy: init module * dap: appease the nix gods (fix statix lint) * flake.lock: fix merge mistake * doc: update release note * fixup! doc: update release note * neo-tree: fix duplicate neo-tree install * lazy: use attrsOf for lazy.plugins * treewide: update lazy.plugins syntax * docs: update lazy.plugins syntax * lazy: cleanup * Update docs/manual/hacking/additional-plugins.md Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> * formatting nitpick Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> * typo tee hee :3 Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> * typo tee hee :4 Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> * flake: update lz.n * lazy: update lz.n plugin spec * lazy: allow lines in place of str for lua code * copilot: lazy load * cmp: lazy load this moves cmp itself to lazy.plugins but other plugins that call cmp are not yet lazy so cmp is technically not yet lazy * luasnip: lazy load * flake: add rtp.nvim * cmp: actually lazy load source * fixup! cmp: actually lazy load source * format * docs: fix broken link * cmp-nvim-lsp: lazy load * lazy: allow key mode of str type * cmp: install sourcess via cmp.sourcePlugins * Update docs/manual/hacking/additional-plugins.md Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com> * lazy: refactor common var * nvim-dap-ui: add setupOpts * refactor: re-order plugin and lz.n configs lazy: make lzn-auto-require togglable * docs: update dag-entries * trouble: remove redundant import * lazy: remove unused module arg * toggleterm: make lazygit keybind optional * toggleterm: use toLuaObject for clarity * surround: rework keymap config * remove stale FIXME * lsp: use cmp_nvim_lsp capabilities * cmp: deduplicate attr key * theme: ensure themes load before lazy plugins * doc: update description of `theme` dag entry * lsp: avoid loading cmp on startup * doc: update configuration docs on custom plugins * cmp: skip trigger_load if lazy disabled * treesitter: remove redundant code * lsp: mark hack as HACK * comment: remove redundant plugin * Squash merge v0.7 into feature/lzn --------- Co-authored-by: raf <raf@notashelf.dev> Co-authored-by: diniamo <55629891+diniamo@users.noreply.github.com>
109 lines
3.1 KiB
Nix
109 lines
3.1 KiB
Nix
{
|
|
lib,
|
|
config,
|
|
...
|
|
}: let
|
|
inherit (builtins) toJSON typeOf head length filter concatLists concatStringsSep;
|
|
inherit (lib.attrsets) mapAttrsToList;
|
|
inherit (lib.modules) mkIf mkMerge;
|
|
inherit (lib.generators) mkLuaInline;
|
|
inherit (lib.strings) optionalString;
|
|
inherit (lib.nvim.lua) toLuaObject;
|
|
inherit (lib.nvim.dag) entryBefore entryAfter;
|
|
cfg = config.vim.lazy;
|
|
|
|
toLuaLznKeySpec = keySpec:
|
|
(removeAttrs keySpec ["key" "lua" "action"])
|
|
// {
|
|
"@1" = keySpec.key;
|
|
"@2" =
|
|
if keySpec.lua
|
|
then mkLuaInline keySpec.action
|
|
else keySpec.action;
|
|
};
|
|
|
|
toLuaLznSpec = name: spec:
|
|
(removeAttrs spec ["package" "setupModule" "setupOpts" "keys"])
|
|
// {
|
|
"@1" = name;
|
|
before =
|
|
if spec.before != null
|
|
then
|
|
mkLuaInline ''
|
|
function()
|
|
${spec.before}
|
|
end
|
|
''
|
|
else null;
|
|
|
|
after =
|
|
if spec.setupModule == null && spec.after == null
|
|
then null
|
|
else
|
|
mkLuaInline ''
|
|
function()
|
|
${
|
|
optionalString (spec.setupModule != null)
|
|
"require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})"
|
|
}
|
|
${optionalString (spec.after != null) spec.after}
|
|
end
|
|
'';
|
|
|
|
keys =
|
|
if typeOf spec.keys == "list" && length spec.keys > 0 && typeOf (head spec.keys) == "set"
|
|
then map toLuaLznKeySpec (filter (keySpec: keySpec.key != null) spec.keys)
|
|
# empty list or str or (listOf str)
|
|
else spec.keys;
|
|
};
|
|
lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins;
|
|
|
|
pluginPackages = mapAttrsToList (_: plugin: plugin.package) cfg.plugins;
|
|
|
|
specToNotLazyConfig = _: spec: ''
|
|
do
|
|
${optionalString (spec.before != null) spec.before}
|
|
${optionalString (spec.setupModule != null)
|
|
"require(${toJSON spec.setupModule}).setup(${toLuaObject spec.setupOpts})"}
|
|
${optionalString (spec.after != null) spec.after}
|
|
end
|
|
'';
|
|
|
|
specToKeymaps = _: spec:
|
|
if typeOf spec.keys == "list"
|
|
then map (x: removeAttrs x ["ft"]) (filter (lznKey: lznKey.action != null && lznKey.ft == null) spec.keys)
|
|
else if spec.keys == null || typeOf spec.keys == "string"
|
|
then []
|
|
else [spec.keys];
|
|
|
|
notLazyConfig =
|
|
concatStringsSep "\n"
|
|
(mapAttrsToList specToNotLazyConfig cfg.plugins);
|
|
|
|
beforeAllJoined =
|
|
concatStringsSep "\n"
|
|
(filter (x: x != null) (mapAttrsToList (_: spec: spec.beforeAll) cfg.plugins));
|
|
in {
|
|
config.vim = mkMerge [
|
|
(mkIf cfg.enable {
|
|
startPlugins = ["lz-n" "lzn-auto-require"];
|
|
|
|
optPlugins = pluginPackages;
|
|
|
|
lazy.builtLazyConfig = ''
|
|
require('lz.n').load(${toLuaObject lznSpecs})
|
|
${optionalString cfg.enableLznAutoRequire "require('lzn-auto-require').enable()"}
|
|
'';
|
|
})
|
|
|
|
(mkIf (!cfg.enable) {
|
|
startPlugins = pluginPackages;
|
|
lazy.builtLazyConfig = ''
|
|
${beforeAllJoined}
|
|
${notLazyConfig}
|
|
'';
|
|
keymaps = concatLists (mapAttrsToList specToKeymaps cfg.plugins);
|
|
})
|
|
];
|
|
}
|