mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-20 16:15:43 +02:00
lib/modules: add applyExtraConfig
Used for - mkVimPlugin: extraConfig - mkNeovimPlugin: extraConfig - mkLsp: extraConfig - mkLsp: settings - mkExtension (telecsope): extraConfig
This commit is contained in:
parent
c7b7b6481b
commit
63cfc84abe
6 changed files with 69 additions and 14 deletions
|
@ -65,7 +65,7 @@ A template plugin can be found in (plugins/TEMPLATE.nix)[https://github.com/nix-
|
|||
| **configLocation** | The location for the Lua configuration. | 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. | No | `{}` |
|
||||
| **extraConfig** | Additional configuration for the plugin. Either an attrset, a function accepting `cfg`, or a function accepting `cfg` and `opts`. | No | `{}` |
|
||||
| **extraOptions** | Module options for the plugin, to be added _outside_ of the `settings` option. These should be Nixvim-specific options. | No | `{}` |
|
||||
| **extraPackages** | Extra packages to include. | No | `[]` |
|
||||
| **extraPlugins** | Extra plugins to include. | No | `[]` |
|
||||
|
@ -126,7 +126,7 @@ Such plugins are usually configured via vim globals, but often have no configura
|
|||
| **colorscheme** | The name of the colorscheme. | No | `name` parameter |
|
||||
| **deprecateExtraConfig** | Flag to deprecate extra configuration. | No | `false` |
|
||||
| **description** | A description of the plugin. Can also be used for non-normative documentation, warnings, tips and tricks. | No | `null` |
|
||||
| **extraConfig** | Extra configuration for the plugin. | No | `cfg: {}` |
|
||||
| **extraConfig** | Extra configuration for the plugin. Either an attrset, a function accepting `cfg`, or a function accepting `cfg` and `opts`. | No | `{}` |
|
||||
| **extraOptions** | Extra options for the plugin. | No | `{}` |
|
||||
| **extraPackages** | Extra packages to include. | No | `[]` |
|
||||
| **extraPlugins** | Extra plugins to include. | No | `[]` |
|
||||
|
|
|
@ -36,6 +36,28 @@ in
|
|||
helpers = self;
|
||||
} // extraSpecialArgs;
|
||||
};
|
||||
|
||||
/**
|
||||
Apply an `extraConfig` definition, which should produce a `config` definition.
|
||||
As used by `mkVimPlugin` and `mkNeovimPlugin`.
|
||||
|
||||
The result will be wrapped using a `mkIf` definition.
|
||||
*/
|
||||
applyExtraConfig =
|
||||
{
|
||||
extraConfig,
|
||||
cfg,
|
||||
opts,
|
||||
enabled ? cfg.enable or (throw "`enabled` argument not provided and no `cfg.enable` option found."),
|
||||
}:
|
||||
let
|
||||
maybeApply = x: maybeFn: if builtins.isFunction maybeFn then maybeFn x else maybeFn;
|
||||
in
|
||||
lib.pipe extraConfig [
|
||||
(maybeApply cfg)
|
||||
(maybeApply opts)
|
||||
(lib.mkIf enabled)
|
||||
];
|
||||
}
|
||||
// lib.mapAttrs (
|
||||
name: msg:
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
}:
|
||||
let
|
||||
cfg = config.${namespace}.${name};
|
||||
opt = options.${namespace}.${name};
|
||||
opts = options.${namespace}.${name};
|
||||
|
||||
setupCode = ''
|
||||
require('${luaName}')${setup}(${
|
||||
|
@ -78,7 +78,7 @@
|
|||
inherit maintainers;
|
||||
nixvimInfo = {
|
||||
inherit description;
|
||||
url = args.url or opt.package.default.meta.homepage;
|
||||
url = args.url or opts.package.default.meta.homepage;
|
||||
path = [
|
||||
namespace
|
||||
name
|
||||
|
@ -146,7 +146,11 @@
|
|||
(lib.optionalAttrs (isColorscheme && (colorscheme != null)) {
|
||||
colorscheme = lib.mkDefault colorscheme;
|
||||
})
|
||||
(extraConfig cfg)
|
||||
(lib.optionalAttrs (args ? extraConfig) (
|
||||
lib.nixvim.modules.applyExtraConfig {
|
||||
inherit extraConfig cfg opts;
|
||||
}
|
||||
))
|
||||
]
|
||||
++ (lib.optionals (!hasConfigAttrs) [
|
||||
(lib.optionalAttrs callSetup (setLuaConfig setupCode))
|
||||
|
|
|
@ -60,14 +60,14 @@
|
|||
}:
|
||||
let
|
||||
cfg = config.${namespace}.${name};
|
||||
opt = options.${namespace}.${name};
|
||||
opts = options.${namespace}.${name};
|
||||
in
|
||||
{
|
||||
meta = {
|
||||
inherit maintainers;
|
||||
nixvimInfo = {
|
||||
inherit description;
|
||||
url = args.url or opt.package.default.meta.homepage;
|
||||
url = args.url or opts.package.default.meta.homepage;
|
||||
path = [
|
||||
namespace
|
||||
name
|
||||
|
@ -115,7 +115,11 @@
|
|||
(lib.optionalAttrs (isColorscheme && (colorscheme != null)) {
|
||||
colorscheme = lib.mkDefault colorscheme;
|
||||
})
|
||||
(extraConfig cfg)
|
||||
(lib.optionalAttrs (args ? extraConfig) (
|
||||
lib.nixvim.modules.applyExtraConfig {
|
||||
inherit extraConfig cfg opts;
|
||||
}
|
||||
))
|
||||
]
|
||||
);
|
||||
};
|
||||
|
|
|
@ -74,7 +74,18 @@ let
|
|||
};
|
||||
};
|
||||
|
||||
extraConfigModule = { config, ... }: extraConfig (getPluginAttr config);
|
||||
extraConfigModule =
|
||||
{
|
||||
lib,
|
||||
config,
|
||||
options,
|
||||
...
|
||||
}:
|
||||
lib.nixvim.modules.applyExtraConfig {
|
||||
inherit extraConfig;
|
||||
cfg = getPluginAttr config;
|
||||
opts = getPluginAttr options;
|
||||
};
|
||||
in
|
||||
{
|
||||
imports = imports ++ [
|
||||
|
|
|
@ -29,14 +29,14 @@
|
|||
with lib;
|
||||
let
|
||||
cfg = config.plugins.lsp.servers.${name};
|
||||
opt = options.plugins.lsp.servers.${name};
|
||||
opts = options.plugins.lsp.servers.${name};
|
||||
|
||||
enabled = config.plugins.lsp.enable && cfg.enable;
|
||||
in
|
||||
{
|
||||
meta.nixvimInfo = {
|
||||
# TODO: description
|
||||
url = args.url or opt.package.default.meta.homepage or null;
|
||||
url = args.url or opts.package.default.meta.homepage or null;
|
||||
path = [
|
||||
"plugins"
|
||||
"lsp"
|
||||
|
@ -70,7 +70,7 @@ in
|
|||
type = with types; nullOr (listOf str);
|
||||
default =
|
||||
# TODO: do we really only want the default `cmd` when `package` is non-null?
|
||||
if !(opt.package.isDefined or false) then
|
||||
if !(opts.package.isDefined or false) then
|
||||
null
|
||||
else if cfg.package == null then
|
||||
null
|
||||
|
@ -150,7 +150,12 @@ in
|
|||
end
|
||||
''
|
||||
);
|
||||
settings = settings cfg.settings;
|
||||
settings = lib.nixvim.modules.applyExtraConfig {
|
||||
extraConfig = settings;
|
||||
cfg = cfg.settings;
|
||||
opts = opts.settings;
|
||||
enabled = true;
|
||||
};
|
||||
} // cfg.extraOptions;
|
||||
}
|
||||
];
|
||||
|
@ -170,8 +175,17 @@ in
|
|||
(mkRemovedOptionModule (
|
||||
basePluginPath ++ [ "extraSettings" ]
|
||||
) "You can use `${basePluginPathString}.extraOptions.settings` instead.")
|
||||
(lib.mkIf enabled (extraConfig cfg))
|
||||
]
|
||||
++ lib.optional (args ? extraConfig) (
|
||||
lib.nixvim.modules.applyExtraConfig {
|
||||
inherit
|
||||
extraConfig
|
||||
cfg
|
||||
opts
|
||||
enabled
|
||||
;
|
||||
}
|
||||
)
|
||||
# Add an alias (with warning) for the lspconfig server name, if different to `name`.
|
||||
# Note: users may use lspconfig's docs to guess the `plugins.lsp.servers.*` name
|
||||
++ (optional (name != serverName) (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue