mirror of
https://github.com/NixOS/nix.git
synced 2024-11-22 06:42:28 +00:00
Merge pull request #11100 from NixOS/pretty-print-idempotent
Pretty print idempotently
This commit is contained in:
commit
b23da1ceca
@ -299,6 +299,9 @@ private:
|
||||
output << ANSI_NORMAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @note This may force items.
|
||||
*/
|
||||
bool shouldPrettyPrintAttrs(AttrVec & v)
|
||||
{
|
||||
if (!options.shouldPrettyPrint() || v.empty()) {
|
||||
@ -315,6 +318,9 @@ private:
|
||||
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
|
||||
// structures.
|
||||
auto itemType = item->type();
|
||||
@ -371,6 +377,9 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @note This may force items.
|
||||
*/
|
||||
bool shouldPrettyPrintList(std::span<Value * const> list)
|
||||
{
|
||||
if (!options.shouldPrettyPrint() || list.empty()) {
|
||||
@ -387,6 +396,9 @@ private:
|
||||
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
|
||||
// structures.
|
||||
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 New Issue
Block a user