mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 08:35:43 +02:00
lib/neovim-plugin: freeform lazy settings
Instead of trying to manage upstream configuration options, just keep using our freeform options so we can do less finicky logic and workarounds.
This commit is contained in:
parent
d24dd313cf
commit
0997b371c7
3 changed files with 103 additions and 118 deletions
|
@ -178,20 +178,14 @@
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
__unkeyed-1 = originalName;
|
__unkeyed-1 = originalName;
|
||||||
# Use provided after, otherwise fallback to normal lua content
|
# Use provided after, otherwise fallback to normal function wrapped lua content
|
||||||
after =
|
after =
|
||||||
if cfg.lazyLoad.settings.after != null then
|
let
|
||||||
cfg.lazyLoad.settings.after
|
after = cfg.lazyLoad.settings.after or null;
|
||||||
else
|
default = "function()\n " + cfg.luaConfig.content + " \nend";
|
||||||
# We need to wrap it in a function so it doesn't execute immediately
|
in
|
||||||
"function()\n " + cfg.luaConfig.content + " \nend";
|
if (lib.isString after || lib.types.rawLua.check after) then after else default;
|
||||||
colorscheme =
|
colorscheme = lib.mkIf isColorscheme (cfg.lazyLoad.settings.colorscheme or colorscheme);
|
||||||
if cfg.lazyLoad.settings.colorscheme != null then
|
|
||||||
cfg.lazyLoad.settings.colorscheme
|
|
||||||
else if (isColorscheme && colorscheme != null) then
|
|
||||||
colorscheme
|
|
||||||
else
|
|
||||||
null;
|
|
||||||
}
|
}
|
||||||
// lib.removeAttrs cfg.lazyLoad.settings [
|
// lib.removeAttrs cfg.lazyLoad.settings [
|
||||||
"after"
|
"after"
|
||||||
|
|
133
lib/options.nix
133
lib/options.nix
|
@ -339,108 +339,47 @@ rec {
|
||||||
lib.mkOption {
|
lib.mkOption {
|
||||||
description = ''
|
description = ''
|
||||||
Lazy-load settings for ${originalName}.
|
Lazy-load settings for ${originalName}.
|
||||||
|
|
||||||
|
> [!WARNING]
|
||||||
|
> This is an experimental option and may not work as expected with all plugins.
|
||||||
|
> The API may change without notice.
|
||||||
|
> Please report any issues you encounter.
|
||||||
'';
|
'';
|
||||||
default = {
|
default = { };
|
||||||
enable = false;
|
type = types.submodule (
|
||||||
};
|
{ config, ... }:
|
||||||
type =
|
{
|
||||||
let
|
options = {
|
||||||
triggerType =
|
enable = lib.mkOption {
|
||||||
with types;
|
default = lib.any (x: x != null) (builtins.attrValues config.settings);
|
||||||
oneOf [
|
defaultText = lib.literalMD ''
|
||||||
rawLua
|
`true` when `settings` has a non-null attribute
|
||||||
str
|
'';
|
||||||
(listOf str)
|
description = ''
|
||||||
];
|
lazy-loading for ${originalName}
|
||||||
in
|
'';
|
||||||
types.submodule (
|
};
|
||||||
{ config, ... }:
|
|
||||||
{
|
|
||||||
options = with defaultNullOpts; {
|
|
||||||
enable = lib.mkOption {
|
|
||||||
default = lib.any (x: x != null) (builtins.attrValues config.settings);
|
|
||||||
description = ''
|
|
||||||
lazy-loading for ${originalName}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
settings = lib.mkOption {
|
settings = lib.nixvim.mkSettingsOption {
|
||||||
description = '''';
|
description = ''
|
||||||
default = { };
|
Lazy provider configuration settings.
|
||||||
type =
|
|
||||||
with types;
|
|
||||||
submodule {
|
|
||||||
freeformType = attrsOf anything;
|
|
||||||
options = {
|
|
||||||
# Spec loading:
|
|
||||||
enabled = mkStrLuaFnOr types.bool null ''
|
|
||||||
When false, or if the function returns false, then ${originalName} will not be included in the spec.
|
|
||||||
|
|
||||||
Equivalence: lz.n => enabled; lazy.nvim => enabled
|
Check your lazy loading provider's documentation on settings to configure.
|
||||||
'';
|
'';
|
||||||
|
example = {
|
||||||
priority = mkNullable types.number null ''
|
cmd = "Neotest";
|
||||||
Only useful for start plugins (not lazy-loaded) to force loading certain plugins first.
|
keys = [
|
||||||
|
{
|
||||||
Equivalence: lz.n => priority; lazy.nvim => priority
|
__unkeyed-1 = "<leader>nt";
|
||||||
'';
|
__unkeyed-3 = "<CMD>Neotest summary<CR>";
|
||||||
|
desc = "Summary toggle";
|
||||||
# Spec setup
|
}
|
||||||
# Actions
|
];
|
||||||
beforeAll = mkLuaFn null ''
|
|
||||||
Always executed before any plugins are loaded.
|
|
||||||
|
|
||||||
Equivalence: lz.n => beforeAll; lazy.nvim => init
|
|
||||||
'';
|
|
||||||
|
|
||||||
before = mkLuaFn null ''
|
|
||||||
Executed before ${originalName} is loaded.
|
|
||||||
|
|
||||||
Equivalence: lz.n => before; lazy.nvim => None
|
|
||||||
'';
|
|
||||||
|
|
||||||
after = mkLuaFn null ''
|
|
||||||
Executed after ${originalName} is loaded.
|
|
||||||
|
|
||||||
Equivalence: lz.n => after; lazy.nvim => config
|
|
||||||
'';
|
|
||||||
|
|
||||||
# Triggers
|
|
||||||
event = mkNullable triggerType null ''
|
|
||||||
Lazy-load on event. Events can be specified as `BufEnter` or with a pattern like `BufEnter *.lua`
|
|
||||||
|
|
||||||
Equivalence: lz.n => event; lazy.nvim => event
|
|
||||||
'';
|
|
||||||
|
|
||||||
cmd = mkNullable triggerType null ''
|
|
||||||
Lazy-load on command.
|
|
||||||
|
|
||||||
Equivalence: lz.n => cmd; lazy.nvim => cmd
|
|
||||||
'';
|
|
||||||
|
|
||||||
ft = mkNullable triggerType null ''
|
|
||||||
Lazy-load on filetype.
|
|
||||||
|
|
||||||
Equivalence: lz.n => ft; lazy.nvim => ft
|
|
||||||
'';
|
|
||||||
|
|
||||||
keys = mkListOf (types.attrsOf types.anything) null ''
|
|
||||||
Lazy-load on key mapping.
|
|
||||||
|
|
||||||
Equivalence: lz.n => keys; lazy.nvim => keys
|
|
||||||
'';
|
|
||||||
|
|
||||||
colorscheme = mkNullable triggerType null ''
|
|
||||||
Lazy-load on colorscheme.
|
|
||||||
|
|
||||||
Equivalence: lz.n => colorscheme; lazy.nvim => None
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
);
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// removed
|
// removed
|
||||||
|
|
|
@ -32,8 +32,8 @@
|
||||||
{
|
{
|
||||||
assertion =
|
assertion =
|
||||||
let
|
let
|
||||||
plugins = config.plugins.lz-n.plugins or [ ];
|
inherit (config.plugins.lz-n) plugins;
|
||||||
plugin = if builtins.length plugins > 0 then builtins.head plugins else null;
|
plugin = if plugins == [ ] then null else builtins.head plugins;
|
||||||
keys = if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ];
|
keys = if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ];
|
||||||
in
|
in
|
||||||
(builtins.length keys) == 1;
|
(builtins.length keys) == 1;
|
||||||
|
@ -42,8 +42,8 @@
|
||||||
{
|
{
|
||||||
assertion =
|
assertion =
|
||||||
let
|
let
|
||||||
plugins = config.plugins.lz-n.plugins or [ ];
|
inherit (config.plugins.lz-n) plugins;
|
||||||
plugin = if builtins.length plugins > 0 then builtins.head plugins else null;
|
plugin = if plugins == [ ] then null else builtins.head plugins;
|
||||||
in
|
in
|
||||||
plugin != null && lib.hasInfix config.plugins.neotest.luaConfig.content plugin.after.__raw;
|
plugin != null && lib.hasInfix config.plugins.neotest.luaConfig.content plugin.after.__raw;
|
||||||
message = "`lz-n.plugins[0].after` should have contained `neotest` lua content.";
|
message = "`lz-n.plugins[0].after` should have contained `neotest` lua content.";
|
||||||
|
@ -126,9 +126,10 @@
|
||||||
assertion =
|
assertion =
|
||||||
let
|
let
|
||||||
plugin = builtins.head config.plugins.lz-n.plugins;
|
plugin = builtins.head config.plugins.lz-n.plugins;
|
||||||
cmd = if builtins.isList plugin.cmd then plugin.cmd else [ ];
|
cmd = plugin.cmd or null;
|
||||||
|
cmd' = lib.optionals (builtins.isList cmd) cmd;
|
||||||
in
|
in
|
||||||
(builtins.length cmd) == 4;
|
(builtins.length cmd') == 4;
|
||||||
message =
|
message =
|
||||||
let
|
let
|
||||||
plugin = builtins.head config.plugins.lz-n.plugins;
|
plugin = builtins.head config.plugins.lz-n.plugins;
|
||||||
|
@ -260,8 +261,8 @@
|
||||||
{
|
{
|
||||||
assertion =
|
assertion =
|
||||||
let
|
let
|
||||||
plugins = config.plugins.lz-n.plugins or [ ];
|
inherit (config.plugins.lz-n) plugins;
|
||||||
plugin = if builtins.length plugins > 0 then builtins.head plugins else null;
|
plugin = if plugins == [ ] then null else builtins.head plugins;
|
||||||
keys = if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ];
|
keys = if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ];
|
||||||
in
|
in
|
||||||
(builtins.length keys) == 1;
|
(builtins.length keys) == 1;
|
||||||
|
@ -282,6 +283,9 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
lazyLoad = {
|
lazyLoad = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
settings = {
|
||||||
|
cmd = [ "Telescope" ];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -301,4 +305,52 @@
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use-provided-raw-after =
|
||||||
|
{ config, ... }:
|
||||||
|
{
|
||||||
|
plugins = {
|
||||||
|
lz-n = {
|
||||||
|
enable = true;
|
||||||
|
};
|
||||||
|
web-devicons.enable = false;
|
||||||
|
telescope = {
|
||||||
|
enable = true;
|
||||||
|
lazyLoad = {
|
||||||
|
enable = true;
|
||||||
|
settings = {
|
||||||
|
after.__raw = ''
|
||||||
|
function()
|
||||||
|
-- test string
|
||||||
|
${config.plugins.telescope.luaConfig.content}
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
cmd = [ "Telescope" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
assertions =
|
||||||
|
let
|
||||||
|
plugin = getFirstLznPlugin config;
|
||||||
|
in
|
||||||
|
[
|
||||||
|
{
|
||||||
|
assertion = (builtins.length config.plugins.lz-n.plugins) == 1;
|
||||||
|
message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
assertion =
|
||||||
|
plugin.after.__raw == ''
|
||||||
|
function()
|
||||||
|
-- test string
|
||||||
|
${config.plugins.telescope.luaConfig.content}
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
message = "`lz-n.plugins[0].after` should have contained a function wrapped `telescope` lua content.";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue