lib.types.attrTag: Fix declarationPositions after merge

This commit is contained in:
Robert Hensing 2024-04-04 12:54:23 +02:00
parent cf4968a904
commit 22d7f146a4
2 changed files with 18 additions and 4 deletions

View file

@ -1,7 +1,8 @@
{ lib, config, ... }: { lib, config, options, ... }:
let let
inherit (lib) mkOption types; inherit (lib) mkOption types;
forceDeep = x: builtins.deepSeq x x; forceDeep = x: builtins.deepSeq x x;
mergedSubOption = (options.merged.type.getSubOptions options.merged.loc).extensible."merged.<name>";
in in
{ {
options = { options = {
@ -98,7 +99,7 @@ in
merged.positive.yay = 100; merged.positive.yay = 100;
merged.extensi-foo.extensible = "foo"; merged.extensi-foo.extensible = "foo";
merged.extensi-bar.extensible = "bar"; merged.extensi-bar.extensible = "bar";
okChecks = okChecks = builtins.addErrorContext "while evaluating the assertions" (
assert config.intStrings.hello == { right = "hello world"; }; assert config.intStrings.hello == { right = "hello world"; };
assert config.intStrings.numberOne == { left = 1; }; assert config.intStrings.numberOne == { left = 1; };
assert config.merged.negative == { nay = false; }; assert config.merged.negative == { nay = false; };
@ -115,7 +116,20 @@ in
assert config.docs."submodules.<name>.qux".visible == true; assert config.docs."submodules.<name>.qux".visible == true;
# Not available (yet?) # Not available (yet?)
# assert config.docs."submodules.<name>.qux".declarationsWithPositions == [ ... ]; # assert config.docs."submodules.<name>.qux".declarationsWithPositions == [ ... ];
assert options.submodules.declarations == [ __curPos.file ];
assert lib.length options.submodules.declarationPositions == 1;
assert (lib.head options.submodules.declarationPositions).file == __curPos.file;
assert options.merged.declarations == [ __curPos.file __curPos.file ];
assert lib.length options.merged.declarationPositions == 2;
assert (lib.elemAt options.merged.declarationPositions 0).file == __curPos.file;
assert (lib.elemAt options.merged.declarationPositions 1).file == __curPos.file;
assert (lib.elemAt options.merged.declarationPositions 0).line != (lib.elemAt options.merged.declarationPositions 1).line;
assert mergedSubOption.declarations == [ __curPos.file __curPos.file ];
assert lib.length mergedSubOption.declarationPositions == 2;
assert (lib.elemAt mergedSubOption.declarationPositions 0).file == __curPos.file;
assert (lib.elemAt mergedSubOption.declarationPositions 1).file == __curPos.file;
assert (lib.elemAt mergedSubOption.declarationPositions 0).line != (lib.elemAt mergedSubOption.declarationPositions 1).line;
assert lib.length config.docs."merged.<name>.extensible".declarations == 2; assert lib.length config.docs."merged.<name>.extensible".declarations == 2;
true; true);
}; };
} }

View file

@ -707,7 +707,7 @@ rec {
// { // {
# mergeOptionDecls is not idempotent in these attrs: # mergeOptionDecls is not idempotent in these attrs:
declarations = a.tags.${tagName}.declarations ++ bOpt.declarations; declarations = a.tags.${tagName}.declarations ++ bOpt.declarations;
declarationPositions = a.tags.${tagName}.declarations ++ bOpt.declarations; declarationPositions = a.tags.${tagName}.declarationPositions ++ bOpt.declarationPositions;
} }
) )
(builtins.intersectAttrs a.tags b.tags); (builtins.intersectAttrs a.tags b.tags);