treewide: move resolveDag to lib

This commit is contained in:
diniamo 2024-07-15 12:15:39 +02:00
parent 714f006a34
commit 4236894566
2 changed files with 24 additions and 24 deletions

View file

@ -8,10 +8,10 @@
# - the addition of the function `entryBefore` indicating a "wanted # - the addition of the function `entryBefore` indicating a "wanted
# by" relationship. # by" relationship.
{lib}: let {lib}: let
inherit (builtins) isAttrs attrValues attrNames elem all head tail length; inherit (builtins) isAttrs attrValues attrNames elem all head tail length toJSON isString;
inherit (lib.attrsets) filterAttrs mapAttrs; inherit (lib.attrsets) filterAttrs mapAttrs;
inherit (lib.lists) toposort; inherit (lib.lists) toposort;
inherit (lib.nvim.dag) empty isEntry entryBetween entryAfter entriesBetween; inherit (lib.nvim.dag) empty isEntry entryBetween entryAfter entriesBetween entryAnywhere topoSort;
in { in {
empty = {}; empty = {};
@ -146,4 +146,23 @@ in {
-- SECTION: ${section.name} -- SECTION: ${section.name}
${section.data} ${section.data}
''; '';
resolveDag = {
name,
dag,
mapResult,
}: let
# When the value is a string, default it to dag.entryAnywhere
finalDag = mapAttrs (_: value:
if isString value
then entryAnywhere value
else value)
dag;
sortedDag = topoSort finalDag;
result =
if sortedDag ? result
then mapResult sortedDag.result
else abort ("Dependency cycle in ${name}: " + toJSON sortedDag);
in
result;
} }

View file

@ -3,15 +3,15 @@
lib, lib,
... ...
}: let }: let
inherit (builtins) map mapAttrs toJSON filter; inherit (builtins) map mapAttrs filter;
inherit (lib.options) mkOption; inherit (lib.options) mkOption;
inherit (lib.attrsets) filterAttrs getAttrs attrValues attrNames; inherit (lib.attrsets) filterAttrs getAttrs attrValues attrNames;
inherit (lib.strings) isString concatLines concatMapStringsSep; inherit (lib.strings) concatLines concatMapStringsSep;
inherit (lib.misc) mapAttrsFlatten; inherit (lib.misc) mapAttrsFlatten;
inherit (lib.trivial) showWarnings; inherit (lib.trivial) showWarnings;
inherit (lib.types) str nullOr; inherit (lib.types) str nullOr;
inherit (lib.generators) mkLuaInline; inherit (lib.generators) mkLuaInline;
inherit (lib.nvim.dag) entryAnywhere entryAfter topoSort mkLuarcSection; inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
inherit (lib.nvim.config) mkBool; inherit (lib.nvim.config) mkBool;
@ -104,25 +104,6 @@ in {
omap = toLuaBindings "o" config.vim.maps.operator; omap = toLuaBindings "o" config.vim.maps.operator;
icmap = toLuaBindings "ic" config.vim.maps.insertCommand; icmap = toLuaBindings "ic" config.vim.maps.insertCommand;
resolveDag = {
name,
dag,
mapResult,
}: let
# When the value is a string, default it to dag.entryAnywhere
finalDag = mapAttrs (_: value:
if isString value
then entryAnywhere value
else value)
dag;
sortedDag = topoSort finalDag;
result =
if sortedDag ? result
then mapResult sortedDag.result
else abort ("Dependency cycle in ${name}: " + toJSON sortedDag);
in
result;
extraPluginConfigs = resolveDag { extraPluginConfigs = resolveDag {
name = "extra plugins config"; name = "extra plugins config";
dag = mapAttrs (_: value: entryAfter value.after value.setup) cfg.extraPlugins; dag = mapAttrs (_: value: entryAfter value.after value.setup) cfg.extraPlugins;