Skip to content

Commit a7e2b90

Browse files
authored
feat(wrapperModules.neovim): added parentName argument in specMods (#222)
1 parent 25e1488 commit a7e2b90

File tree

3 files changed

+105
-50
lines changed

3 files changed

+105
-50
lines changed

templates/neovim/module.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,14 @@ inputs:
173173
{
174174
# When this module is ran in an inner list,
175175
# this will contain `config` of the parent spec
176-
parentSpec,
176+
parentSpec ? null,
177177
# and this will contain `options`
178178
# otherwise they will be `null`
179-
parentOpts,
179+
parentOpts ? null,
180+
parentName ? null,
180181
# and then config from this one, as normal
181182
config,
183+
# and the other module arguments.
182184
...
183185
}:
184186
{

wrapperModules/n/neovim/module.nix

Lines changed: 98 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -224,49 +224,67 @@ in
224224
);
225225
};
226226
specs = lib.mkOption {
227-
type =
228-
wlib.dag.dagWith
229-
{
230-
modules = [ config.specMods ];
231-
specialArgs = {
232-
parentSpec = null;
233-
parentOpts = null;
234-
};
235-
dataTypeFn =
236-
let
237-
inherit (config) specMods;
238-
in
239-
elemType:
240-
{
241-
config,
242-
options,
243-
...
244-
}:
245-
types.nullOr (
246-
types.either wlib.types.stringable (
247-
wlib.dag.dalWith {
248-
modules = [ specMods ];
249-
specialArgs = {
250-
parentSpec = config;
251-
parentOpts = options;
252-
};
253-
} (types.nullOr wlib.types.stringable)
254-
)
255-
);
256-
}
257-
(
258-
types.nullOr (
259-
types.either wlib.types.stringable (
260-
wlib.dag.dalWith {
261-
modules = [ config.specMods ];
262-
specialArgs = {
263-
parentSpec = null;
264-
parentOpts = null;
227+
type = lib.types.attrsOf (
228+
wlib.types.specWith {
229+
specialArgs = {
230+
parentSpec = null;
231+
parentOpts = null;
232+
parentName = null;
233+
};
234+
modules =
235+
let
236+
inherit (config) specMods;
237+
in
238+
[
239+
(
240+
{
241+
config,
242+
options,
243+
name,
244+
...
245+
}:
246+
{
247+
options.data = lib.mkOption {
248+
description = ''
249+
A list of specs or plugins, or a plugin, or null
250+
251+
A plugin can be a derivation,
252+
or an impure string path for testing!
253+
'';
254+
type = types.nullOr (
255+
lib.types.either wlib.types.stringable (
256+
types.listOf (
257+
wlib.types.specWith {
258+
specialArgs = {
259+
parentSpec = config;
260+
parentOpts = options;
261+
parentName = name;
262+
};
263+
modules = [
264+
{
265+
options.data = lib.mkOption {
266+
type = types.nullOr wlib.types.stringable;
267+
description = ''
268+
A plugin (or null)
269+
270+
A plugin can be a derivation,
271+
or an impure string path for testing!
272+
'';
273+
};
274+
}
275+
specMods
276+
];
277+
}
278+
)
279+
)
280+
);
265281
};
266-
} (types.nullOr wlib.types.stringable)
282+
}
267283
)
268-
)
269-
);
284+
specMods
285+
];
286+
}
287+
);
270288
default = { };
271289
description = builtins.readFile ./spec_desc.md;
272290
};
@@ -384,23 +402,29 @@ in
384402
specMods = lib.mkOption {
385403
default = { };
386404
description = ''
387-
extra module for the plugin spec submodules (provided to `wlib.dag.dagWith` or `wlib.dag.dalWith`)
405+
extra module for the plugin spec submodules (provided to `wlib.types.specWith`)
406+
407+
These modules recieve some `specialArgs`!
388408
389-
These modules recieve `parentSpec` and `parentOpts` via `specialArgs`
409+
`parentSpec`, `parentOpts`, and `parentName`
390410
391-
If the spec is a parent, this will be `null`
411+
If the spec is a parent, these will be `null`
392412
393-
If the spec is a child, it will be the `config` argument of the parent spec.
413+
If the spec is a child, `parentSpec` will be the `config` argument of the parent spec.
414+
415+
Likewise, `parentOpts` will be the `options` argument and `parentName` the name argument.
394416
395417
You may use this to change defaults and allow parent overrides of the default to propagate default values to child specs.
396418
397419
```nix
398-
config.specMods = { parentSpec, ... }: {
420+
config.specMods = {
421+
parentSpec, config, parentOpts, options, parentName, ...
422+
}: {
399423
config.collateGrammars = lib.mkDefault (parentSpec.collateGrammars or false);
400424
};
401425
```
402426
403-
You could also declare entirely new items for the spec to process in `specMaps` and `specCollect`.
427+
You could also declare entirely new items for the spec to process with `specMaps` and `specCollect`.
404428
'';
405429
type = types.deferredModuleWith {
406430
staticModules = [
@@ -410,10 +434,13 @@ in
410434
options,
411435
parentSpec ? null,
412436
parentOpts ? null,
437+
parentName ? null,
438+
name,
413439
...
414440
}:
415441
{
416442
# NOTE: for docgen
443+
config._module.args.parentName = lib.mkOptionDefault null;
417444
config._module.args.parentSpec = lib.mkOptionDefault null;
418445
config._module.args.parentOpts = lib.mkOptionDefault null;
419446
options = {
@@ -426,6 +453,30 @@ in
426453
If this is in the inner list, then the default value from the parent spec will be used.
427454
'';
428455
};
456+
name = lib.mkOption {
457+
type = types.nullOr types.str;
458+
default = if parentName != null then null else name;
459+
description = ''
460+
The name of this spec in the DAG of specs
461+
462+
May differ from the name of the plugin,
463+
which is controlled by the `pname` option.
464+
'';
465+
};
466+
before = lib.mkOption {
467+
type = with types; listOf str;
468+
default = [ ];
469+
description = ''
470+
Sort this spec before the list of spec names
471+
'';
472+
};
473+
after = lib.mkOption {
474+
type = types.listOf types.str;
475+
default = [ ];
476+
description = ''
477+
Sort this spec after the list of spec names
478+
'';
479+
};
429480
pname = lib.mkOption {
430481
type = types.nullOr types.str;
431482
default = null;

wrapperModules/n/neovim/post_desc.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ You have full control over them via the module system! This module will apply to
176176

177177
In the outer set, `parentSpec` is `null` and in the inner lists, it receives the `config` argument from the outer set!
178178

179-
It also receives `parentOpts`, which contains the `options` argument.
179+
It also receives `parentOpts`, which contains the `options` argument, and `parentName` with the name argument of the outer spec.
180+
181+
It also receives the normal module arguments, like `config` from the current module.
180182

181183
---
182184

0 commit comments

Comments
 (0)