Compare commits

..

No commits in common. "b59689dbd94aef129359ef0d3b4907543fc38e1f" and "70e988bb33551cc1bbd5bc1b2112f0f45cd28f86" have entirely different histories.

15 changed files with 104 additions and 120 deletions

View file

@ -15,11 +15,9 @@ entries in nvf:
5. `theme` (this is simply placed before `pluginConfigs`, meaning that 5. `theme` (this is simply placed before `pluginConfigs`, meaning that
surrounding entries don't depend on it) - used to set up the theme, which has surrounding entries don't depend on it) - used to set up the theme, which has
to be done before other plugins to be done before other plugins
6. `lazyConfigs` - `lz.n` and `lzn-auto-require` configs. If `vim.lazy.enable` 6. `pluginConfigs` - the result of the nested `vim.pluginRC` (internal option,
is false, this will contain each plugin's config instead.
7. `pluginConfigs` - the result of the nested `vim.pluginRC` (internal option,
see the [Custom Plugins](/index.xhtml#ch-custom-plugins) page for adding your see the [Custom Plugins](/index.xhtml#ch-custom-plugins) page for adding your
own plugins) DAG, used to set up internal plugins own plugins) DAG, used to set up internal plugins
8. `extraPluginConfigs` - the result of `vim.extraPlugins`, which is not a 7. `extraPluginConfigs` - the result of `vim.extraPlugins`, which is not a
direct DAG, but is converted to, and resolved as one internally direct DAG, but is converted to, and resolved as one internally
9. `mappings` - the result of `vim.maps` 8. `mappings` - the result of `vim.maps`

View file

@ -162,7 +162,7 @@ in {
} }
``` ```
This results in the following lua code: This results in the lua code:
```lua ```lua
require('lz.n').load({ require('lz.n').load({
{ {

View file

@ -56,12 +56,21 @@ in {
(mkLuaKeymap ["i"] cfg.mappings.suggestion.prev "function() require('copilot.suggestion').prev() end" "[copilot] previous suggestion" {}) (mkLuaKeymap ["i"] cfg.mappings.suggestion.prev "function() require('copilot.suggestion').prev() end" "[copilot] previous suggestion" {})
]; ];
}; };
copilot-cmp = mkIf cfg.cmp.enable {
package = "copilot-cmp";
lazy = true;
after = optionalString config.vim.lazy.enable ''
local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/copilot-cmp')
require("rtp_nvim").source_after_plugin_dir(path)
require("lz.n").trigger_load("copilot-lua")
'';
};
nvim-cmp.after = mkIf cfg.cmp.enable "require('lz.n').trigger_load('copilot-cmp')";
}; };
autocomplete.nvim-cmp = { autocomplete.nvim-cmp.sources = {copilot = "[Copilot]";};
sources = {copilot = "[Copilot]";};
sourcePlugins = ["copilot-cmp"];
};
# Disable plugin handled keymaps. # Disable plugin handled keymaps.
# Setting it here so that it doesn't show up in user docs # Setting it here so that it doesn't show up in user docs

View file

@ -3,57 +3,56 @@
config, config,
... ...
}: let }: let
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf;
inherit (lib.strings) optionalString; inherit (lib.strings) optionalString;
inherit (lib.generators) mkLuaInline; inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.attrsets) mapListToAttrs; inherit (builtins) attrNames;
inherit (builtins) attrNames typeOf tryEval concatStringsSep;
cfg = config.vim.autocomplete.nvim-cmp; cfg = config.vim.autocomplete.nvim-cmp;
luasnipEnable = config.vim.snippets.luasnip.enable; luasnipEnable = config.vim.snippets.luasnip.enable;
getPluginName = plugin:
if typeOf plugin == "string"
then plugin
else if (plugin ? pname && (tryEval plugin.pname).success)
then plugin.pname
else plugin.name;
inherit (cfg) mappings; inherit (cfg) mappings;
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim = { vim = {
startPlugins = ["rtp-nvim"]; startPlugins = ["rtp-nvim"];
lazy.plugins = mkMerge [ lazy.plugins = {
(mapListToAttrs (package: { # cmp sources are loaded via lzn-auto-require as long as it is defined
name = getPluginName package; # in cmp sources
value = { cmp-buffer = {
inherit package; package = "cmp-buffer";
lazy = true; lazy = true;
after = '' after = ''
local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/${getPluginName package}') local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/cmp-buffer')
require("rtp_nvim").source_after_plugin_dir(path) require("rtp_nvim").source_after_plugin_dir(path)
''; '';
}; };
}) cmp-path = {
cfg.sourcePlugins) package = "cmp-path";
{ lazy = true;
nvim-cmp = { after = ''
package = "nvim-cmp"; local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/cmp-path')
after = '' require("rtp_nvim").source_after_plugin_dir(path)
${optionalString luasnipEnable "local luasnip = require('luasnip')"} '';
require("lz.n").trigger_load("cmp-path") };
local cmp = require("cmp") nvim-cmp = {
cmp.setup(${toLuaObject cfg.setupOpts}) package = "nvim-cmp";
after = ''
${optionalString luasnipEnable "local luasnip = require('luasnip')"}
require("lz.n").trigger_load("cmp-path")
local cmp = require("cmp")
cmp.setup(${toLuaObject cfg.setupOpts})
${concatStringsSep "\n" (map ${
(package: "require('lz.n').trigger_load(${toLuaObject (getPluginName package)})") optionalString config.vim.lazy.enable ''
cfg.sourcePlugins)} require("lz.n").trigger_load("cmp-buffer")
''; ''
}
'';
event = ["InsertEnter" "CmdlineEnter"]; event = ["InsertEnter" "CmdlineEnter"];
}; };
} };
];
autocomplete.nvim-cmp = { autocomplete.nvim-cmp = {
sources = { sources = {
@ -62,8 +61,6 @@ in {
path = "[Path]"; path = "[Path]";
}; };
sourcePlugins = ["cmp-buffer" "cmp-path"];
setupOpts = { setupOpts = {
sources = map (s: {name = s;}) (attrNames cfg.sources); sources = map (s: {name = s;}) (attrNames cfg.sources);

View file

@ -4,10 +4,10 @@
... ...
}: let }: let
inherit (lib.options) mkEnableOption mkOption literalExpression literalMD; inherit (lib.options) mkEnableOption mkOption literalExpression literalMD;
inherit (lib.types) str attrsOf nullOr either listOf; inherit (lib.types) str attrsOf nullOr either;
inherit (lib.generators) mkLuaInline; inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption luaInline mergelessListOf pluginType; inherit (lib.nvim.types) mkPluginSetupOption luaInline mergelessListOf;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
inherit (builtins) isString; inherit (builtins) isString;
@ -99,11 +99,5 @@ in {
} }
''; '';
}; };
sourcePlugins = mkOption {
type = listOf pluginType;
default = [];
description = "List of source plugins used by nvim-cmp.";
};
}; };
} }

View file

@ -57,7 +57,7 @@ in {
lazy.plugins.nvim-dap-ui = { lazy.plugins.nvim-dap-ui = {
package = "nvim-dap-ui"; package = "nvim-dap-ui";
setupModule = "dapui"; setupModule = "dapui";
inherit (cfg.ui) setupOpts; setupOpts = {};
keys = [ keys = [
(mkSetLuaLznBinding mappings.toggleDapUI "function() require('dapui').toggle() end") (mkSetLuaLznBinding mappings.toggleDapUI "function() require('dapui').toggle() end")

View file

@ -2,16 +2,12 @@
inherit (lib.options) mkEnableOption mkOption; inherit (lib.options) mkEnableOption mkOption;
inherit (lib.types) bool attrsOf str; inherit (lib.types) bool attrsOf str;
inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption;
in { in {
options.vim.debugger.nvim-dap = { options.vim.debugger.nvim-dap = {
enable = mkEnableOption "debugging via nvim-dap"; enable = mkEnableOption "debugging via nvim-dap";
ui = { ui = {
enable = mkEnableOption "UI extension for nvim-dap"; enable = mkEnableOption "UI extension for nvim-dap";
setupOpts = mkPluginSetupOption "nvim-dap-ui" {};
autoStart = mkOption { autoStart = mkOption {
type = bool; type = bool;
default = true; default = true;

View file

@ -5,6 +5,7 @@
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.lists) optional;
inherit (lib.strings) optionalString; inherit (lib.strings) optionalString;
inherit (lib.trivial) boolToString; inherit (lib.trivial) boolToString;
inherit (lib.nvim.binds) addDescriptionsToMappings; inherit (lib.nvim.binds) addDescriptionsToMappings;
@ -22,11 +23,20 @@
in { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim = { vim = {
autocomplete.nvim-cmp = { lazy.plugins = {
sources = {nvim_lsp = "[LSP]";}; cmp-nvim-lsp = {
sourcePlugins = ["cmp-nvim-lsp"]; package = "cmp-nvim-lsp";
lazy = true;
after = ''
local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/cmp-treesitter')
require("rtp_nvim").source_after_plugin_dir(path)
'';
};
nvim-cmp.after = mkIf usingNvimCmp "require('lz.n').trigger_load('cmp-nvim-lsp')";
}; };
autocomplete.nvim-cmp.sources = {nvim_lsp = "[LSP]";};
pluginRC.lsp-setup = '' pluginRC.lsp-setup = ''
vim.g.formatsave = ${boolToString cfg.formatOnSave}; vim.g.formatsave = ${boolToString cfg.formatOnSave};
@ -116,7 +126,7 @@ in {
end end
local capabilities = vim.lsp.protocol.make_client_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities()
-- ${optionalString usingNvimCmp "capabilities = require('cmp_nvim_lsp').default_capabilities()"} ${optionalString usingNvimCmp "capabilities = require('cmp_nvim_lsp').default_capabilities()"}
''; '';
}; };
}; };

View file

@ -1,7 +1,6 @@
{ {
config, config,
lib, lib,
options,
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
@ -9,7 +8,8 @@
cfg = config.vim.lsp; cfg = config.vim.lsp;
mappingDefinitions = options.vim.lsp.trouble.mappings; self = import ./trouble.nix {inherit lib;};
mappingDefinitions = self.options.vim.lsp.trouble.mappings;
mappings = addDescriptionsToMappings cfg.trouble.mappings mappingDefinitions; mappings = addDescriptionsToMappings cfg.trouble.mappings mappingDefinitions;
in { in {
config = mkIf (cfg.enable && cfg.trouble.enable) { config = mkIf (cfg.enable && cfg.trouble.enable) {

View file

@ -4,6 +4,7 @@
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.strings) optionalString;
cfg = config.vim.snippets.luasnip; cfg = config.vim.snippets.luasnip;
in { in {
@ -15,12 +16,20 @@ in {
lazy = true; lazy = true;
after = cfg.loaders; after = cfg.loaders;
}; };
cmp-luasnip = mkIf config.vim.autocomplete.nvim-cmp.enable {
package = "cmp-luasnip";
lazy = true;
after = ''
local path = vim.fn.globpath(vim.o.packpath, 'pack/*/opt/cmp-luasnip')
require("rtp_nvim").source_after_plugin_dir(path)
'';
};
nvim-cmp.after = optionalString config.vim.lazy.enable ''
require("lz.n").trigger_load("cmp-luasnip")
'';
}; };
startPlugins = cfg.providers; startPlugins = cfg.providers;
autocomplete.nvim-cmp = { autocomplete.nvim-cmp.sources = {luasnip = "[LuaSnip]";};
sources = {luasnip = "[LuaSnip]";};
sourcePlugins = ["cmp-luasnip"];
};
}; };
}; };
} }

View file

@ -5,7 +5,7 @@
... ...
}: let }: let
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf mkMerge;
inherit (lib.lists) optionals; inherit (lib.lists) optional optionals;
inherit (lib.nvim.binds) mkSetBinding addDescriptionsToMappings; inherit (lib.nvim.binds) mkSetBinding addDescriptionsToMappings;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.dag) entryBefore entryAfter; inherit (lib.nvim.dag) entryBefore entryAfter;
@ -32,11 +32,7 @@ in {
nvim-cmp.after = mkIf usingNvimCmp "require('lz.n').trigger_load('cmp-treesitter')"; nvim-cmp.after = mkIf usingNvimCmp "require('lz.n').trigger_load('cmp-treesitter')";
}; };
autocomplete.nvim-cmp = { autocomplete.nvim-cmp.sources = {treesitter = "[Treesitter]";};
sources = {treesitter = "[Treesitter]";};
sourcePlugins = ["cmp-treesitter"];
};
treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars; treesitter.grammars = optionals cfg.addDefaultGrammars cfg.defaultGrammars;
maps = { maps = {

View file

@ -1,6 +1,6 @@
{ {
options,
config, config,
pkgs,
lib, lib,
... ...
}: let }: let
@ -11,7 +11,8 @@
inherit (lib.nvim.binds) pushDownDefault mkSetLznBinding; inherit (lib.nvim.binds) pushDownDefault mkSetLznBinding;
cfg = config.vim.telescope; cfg = config.vim.telescope;
mappingDefinitions = options.vim.telescope.mappings; self = import ./telescope.nix {inherit pkgs lib;};
mappingDefinitions = self.options.vim.telescope.mappings;
mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions;
in { in {

View file

@ -58,8 +58,6 @@
}; };
lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins; lznSpecs = mapAttrsToList toLuaLznSpec cfg.plugins;
pluginPackages = mapAttrsToList (_: plugin: plugin.package) cfg.plugins;
specToNotLazyConfig = _: spec: '' specToNotLazyConfig = _: spec: ''
do do
${optionalString (spec.before != null) spec.before} ${optionalString (spec.before != null) spec.before}
@ -76,32 +74,25 @@
then [] then []
else [spec.keys]; else [spec.keys];
notLazyConfig = notLazyConfig = concatStringsSep "\n" (mapAttrsToList specToNotLazyConfig cfg.plugins);
concatStringsSep "\n"
(mapAttrsToList specToNotLazyConfig cfg.plugins);
beforeAllJoined =
concatStringsSep "\n"
(filter (x: x != null) (mapAttrsToList (_: spec: spec.beforeAll) cfg.plugins));
in { in {
config.vim = mkMerge [ config.vim = mkMerge [
(mkIf cfg.enable { (mkIf cfg.enable {
startPlugins = ["lz-n" "lzn-auto-require"]; startPlugins = ["lz-n" "lzn-auto-require"];
optPlugins = pluginPackages; optPlugins = mapAttrsToList (_: plugin: plugin.package) cfg.plugins;
lazy.builtLazyConfig = '' luaConfigRC.lzn-load = entryBefore ["pluginConfigs"] ''
require('lz.n').load(${toLuaObject lznSpecs}) require('lz.n').load(${toLuaObject lznSpecs})
${optionalString cfg.enableLznAutoRequire "require('lzn-auto-require').enable()"}
''; '';
}) })
(mkIf (!cfg.enable) { (mkIf (!cfg.enable) {
startPlugins = pluginPackages; startPlugins = mapAttrsToList (_: plugin: plugin.package) cfg.plugins;
lazy.builtLazyConfig = '' luaConfigPre =
${beforeAllJoined} concatStringsSep "\n"
${notLazyConfig} (filter (x: x != null) (mapAttrsToList (_: spec: spec.beforeAll) cfg.plugins));
''; luaConfigRC.unlazy = entryAfter ["pluginConfigs"] notLazyConfig;
keymaps = concatLists (mapAttrsToList specToKeymaps cfg.plugins); keymaps = concatLists (mapAttrsToList specToKeymaps cfg.plugins);
}) })
]; ];

View file

@ -35,7 +35,7 @@
mode = mkOption { mode = mkOption {
description = "Modes to bind in"; description = "Modes to bind in";
type = either str (listOf str); type = listOf str;
default = ["n" "x" "s" "o"]; default = ["n" "x" "s" "o"];
}; };
@ -181,7 +181,7 @@
}; };
in { in {
options.vim.lazy = { options.vim.lazy = {
enable = mkEnableOption "plugin lazy-loading via lz.n and lzn-auto-require" // {default = true;}; enable = mkEnableOption "plugin lazy-loading" // {default = true;};
loader = mkOption { loader = mkOption {
description = "Lazy loader to use"; description = "Lazy loader to use";
type = enum ["lz.n"]; type = enum ["lz.n"];
@ -215,23 +215,5 @@ in {
} }
''; '';
}; };
enableLznAutoRequire = mkOption {
description = ''
Enable lzn-auto-require. Since builtin plugins rely on this, only turn
off for debugging.
'';
type = bool;
default = true;
};
builtLazyConfig = mkOption {
internal = true;
type = lines;
description = ''
The built config for lz.n, or if `vim.lazy.enable` is false, the
individual plugin configs.
'';
};
}; };
} }

View file

@ -52,10 +52,11 @@ in {
optionsScript = entryAfter ["basic"] (concatLines optionsScript); optionsScript = entryAfter ["basic"] (concatLines optionsScript);
# Basic # Basic
lazyConfigs = entryAfter ["optionsScript"] cfg.lazy.builtLazyConfig; pluginConfigs = entryAfter ["optionsScript"] pluginConfigs;
pluginConfigs = entryAfter ["lazyConfigs"] pluginConfigs;
extraPluginConfigs = entryAfter ["pluginConfigs"] extraPluginConfigs; extraPluginConfigs = entryAfter ["pluginConfigs"] extraPluginConfigs;
mappings = entryAfter ["extraPluginConfigs"] keymaps; mappings = entryAfter ["extraPluginConfigs"] keymaps;
# FIXME: put this somewhere less stupid
footer = entryAfter ["mappings"] (optionalString config.vim.lazy.enable "require('lzn-auto-require').enable()");
}; };
builtLuaConfigRC = let builtLuaConfigRC = let