mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-20 16:15:43 +02:00
lib/neovim-plugin: allow configLocation
to be wrapped using mkOrder
This commit is contained in:
parent
c181014422
commit
6a192a8604
4 changed files with 41 additions and 4 deletions
|
@ -62,7 +62,7 @@ A template plugin can be found in (plugins/TEMPLATE.nix)[https://github.com/nix-
|
|||
| **url** | The URL of the plugin's repository. | Yes | `package` parameter's `meta.homepage` |
|
||||
| **callSetup** | Indicating whether to call the setup function. Useful when `setup` function needs customizations. | No | `true` |
|
||||
| **colorscheme** | The name of the colorscheme. | No | `name` parameter |
|
||||
| **configLocation** | The location for the Lua configuration. | No | `"extraConfigLuaPre"` if `isColorscheme` then `extraConfigLuaPre`, otherwise `"extraConfigLua"` |
|
||||
| **configLocation** | The option location where the lua configuration should be installed. Nested option locations can be represented as a list. The location can also be wrapped using `lib.mkBefore`, `lib.mkAfter`, or `lib.mkOrder`. | No | `"extraConfigLuaPre"` if `isColorscheme` then `extraConfigLuaPre`, otherwise `"extraConfigLua"` |
|
||||
| **deprecateExtraOptions** | Indicating whether to deprecate the `extraOptions` attribute. Mainly used for old plugins. | No | `false` |
|
||||
| **description** | A brief description of the plugin. Can also be used for non-normative documentation, warnings, tips and tricks. | No | `null` |
|
||||
| **extraConfig** | Additional configuration for the plugin. Either an attrset, a function accepting `cfg`, or a function accepting `cfg` and `opts`. | No | `{}` |
|
||||
|
|
|
@ -58,6 +58,15 @@ in
|
|||
(maybeApply opts)
|
||||
(lib.mkIf enabled)
|
||||
];
|
||||
|
||||
mkConfigAt =
|
||||
loc: def:
|
||||
let
|
||||
isOrder = loc._type or null == "order";
|
||||
withOrder = if isOrder then lib.modules.mkOrder loc.priority else lib.id;
|
||||
loc' = lib.toList (if isOrder then loc.content else loc);
|
||||
in
|
||||
lib.setAttrByPath loc' (withOrder def);
|
||||
}
|
||||
// lib.mapAttrs (
|
||||
name: msg:
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
})
|
||||
'';
|
||||
|
||||
setLuaConfig = lib.setAttrByPath (lib.toList configLocation);
|
||||
luaConfigAtLocation = lib.nixvim.modules.mkConfigAt configLocation cfg.luaConfig.content;
|
||||
in
|
||||
{
|
||||
meta = {
|
||||
|
@ -162,8 +162,8 @@
|
|||
# Add the plugin setup code `require('foo').setup(...)` to the lua configuration
|
||||
(lib.optionalAttrs callSetup { ${namespace}.${name}.luaConfig.content = setupCode; })
|
||||
|
||||
# Write the lua configuration `luaConfig.content` to the config file when lazy loading is not enabled
|
||||
(lib.mkIf (!cfg.lazyLoad.enable) (setLuaConfig cfg.luaConfig.content))
|
||||
# When NOT lazy loading, write `luaConfig.content` to `configLocation`
|
||||
(lib.mkIf (!cfg.lazyLoad.enable) luaConfigAtLocation)
|
||||
|
||||
# When lazy loading is enabled for this plugin, route its configuration to the enabled provider
|
||||
(lib.mkIf cfg.lazyLoad.enable {
|
||||
|
|
|
@ -451,6 +451,34 @@ let
|
|||
EOFFF'';
|
||||
};
|
||||
};
|
||||
|
||||
testMkLuaConfig = {
|
||||
expr = lib.mapAttrs (_: loc: helpers.modules.mkConfigAt loc "Hello!") {
|
||||
"simple string" = "foo";
|
||||
"simple list" = [
|
||||
"foo"
|
||||
"bar"
|
||||
];
|
||||
"mkBefore string" = lib.mkBefore "foo";
|
||||
"mkBefore list" = lib.mkBefore [
|
||||
"foo"
|
||||
"bar"
|
||||
];
|
||||
"mkAfter string" = lib.mkAfter "foo";
|
||||
"mkAfter list" = lib.mkAfter [
|
||||
"foo"
|
||||
"bar"
|
||||
];
|
||||
};
|
||||
expected = {
|
||||
"simple string".foo = "Hello!";
|
||||
"simple list".foo.bar = "Hello!";
|
||||
"mkBefore string".foo = lib.mkBefore "Hello!";
|
||||
"mkBefore list".foo.bar = lib.mkBefore "Hello!";
|
||||
"mkAfter string".foo = lib.mkAfter "Hello!";
|
||||
"mkAfter list".foo.bar = lib.mkAfter "Hello!";
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
if results == [ ] then
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue