mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 05:56:15 +02:00
Merge pull request #11100 from NixOS/pretty-print-idempotent
Pretty print idempotently
This commit is contained in:
commit
b23da1ceca
4 changed files with 69 additions and 0 deletions
|
@ -299,6 +299,9 @@ private:
|
||||||
output << ANSI_NORMAL;
|
output << ANSI_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @note This may force items.
|
||||||
|
*/
|
||||||
bool shouldPrettyPrintAttrs(AttrVec & v)
|
bool shouldPrettyPrintAttrs(AttrVec & v)
|
||||||
{
|
{
|
||||||
if (!options.shouldPrettyPrint() || v.empty()) {
|
if (!options.shouldPrettyPrint() || v.empty()) {
|
||||||
|
@ -315,6 +318,9 @@ private:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// It is ok to force the item(s) here, because they will be printed anyway.
|
||||||
|
state.forceValue(*item, item->determinePos(noPos));
|
||||||
|
|
||||||
// Pretty-print single-item attrsets only if they contain nested
|
// Pretty-print single-item attrsets only if they contain nested
|
||||||
// structures.
|
// structures.
|
||||||
auto itemType = item->type();
|
auto itemType = item->type();
|
||||||
|
@ -371,6 +377,9 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @note This may force items.
|
||||||
|
*/
|
||||||
bool shouldPrettyPrintList(std::span<Value * const> list)
|
bool shouldPrettyPrintList(std::span<Value * const> list)
|
||||||
{
|
{
|
||||||
if (!options.shouldPrettyPrint() || list.empty()) {
|
if (!options.shouldPrettyPrint() || list.empty()) {
|
||||||
|
@ -387,6 +396,9 @@ private:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// It is ok to force the item(s) here, because they will be printed anyway.
|
||||||
|
state.forceValue(*item, item->determinePos(noPos));
|
||||||
|
|
||||||
// Pretty-print single-item lists only if they contain nested
|
// Pretty-print single-item lists only if they contain nested
|
||||||
// structures.
|
// structures.
|
||||||
auto itemType = item->type();
|
auto itemType = item->type();
|
||||||
|
|
29
tests/functional/repl/pretty-print-idempotent.expected
Normal file
29
tests/functional/repl/pretty-print-idempotent.expected
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
Nix <nix version>
|
||||||
|
Type :? for help.
|
||||||
|
Added <number omitted> variables.
|
||||||
|
|
||||||
|
{ homepage = "https://example.com"; }
|
||||||
|
|
||||||
|
{ homepage = "https://example.com"; }
|
||||||
|
|
||||||
|
{
|
||||||
|
layerOne = { ... };
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
layerOne = { ... };
|
||||||
|
}
|
||||||
|
|
||||||
|
[ "https://example.com" ]
|
||||||
|
|
||||||
|
[ "https://example.com" ]
|
||||||
|
|
||||||
|
[
|
||||||
|
[ ... ]
|
||||||
|
]
|
||||||
|
|
||||||
|
[
|
||||||
|
[ ... ]
|
||||||
|
]
|
||||||
|
|
||||||
|
|
9
tests/functional/repl/pretty-print-idempotent.in
Normal file
9
tests/functional/repl/pretty-print-idempotent.in
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
:l pretty-print-idempotent.nix
|
||||||
|
oneDeep
|
||||||
|
oneDeep
|
||||||
|
twoDeep
|
||||||
|
twoDeep
|
||||||
|
oneDeepList
|
||||||
|
oneDeepList
|
||||||
|
twoDeepList
|
||||||
|
twoDeepList
|
19
tests/functional/repl/pretty-print-idempotent.nix
Normal file
19
tests/functional/repl/pretty-print-idempotent.nix
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
oneDeep = {
|
||||||
|
homepage = "https://" + "example.com";
|
||||||
|
};
|
||||||
|
twoDeep = {
|
||||||
|
layerOne = {
|
||||||
|
homepage = "https://" + "example.com";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
oneDeepList = [
|
||||||
|
("https://" + "example.com")
|
||||||
|
];
|
||||||
|
twoDeepList = [
|
||||||
|
[
|
||||||
|
("https://" + "example.com")
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
Loading…
Reference in a new issue