New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
libexpr: extend Value::print
to allow limited depth
#8566
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say a depth parameter is a last resource, but a valid solution that's fairly easy to implement and maintain. You might want to consider, although you probably already have:
- only explore one layer at a time, lazily, on-demand, interactive, etc
- a mix of "depth first" and "breadth first" until you reach an output size limit; some clever balancing act. Should work reasonably even for
pkgs
. - depth limit. The minimum limit is still terrible for something like
pkgs
Assuming 1 is not feasible for you and 2 is a "research project" and a lot more to test and review, let's go ahead with this.
This needs testing. Ideally I'd like to see a new unit test in src/libexpr/tests (I hate to say that this function is not unit tested yet), but perhaps it would also be nice to have a depth parameter for nix-instantiate
, which uses this method.
Thanks for reviewing my PRs 鉂わ笍 .
Before addressing review comments, would you like to accept patches that trying to stop printing to
Yes, it gives us reasonable outputs because nix language itself is structural and nested, so given a "depth" argument somehow preserve enough information instead of digging in some irrelavent attribute paths.
Thanks, I would like to see how to add these tests then. |
You can refer to the existing tests as examples of how to set them up.
|
bf0b67d
to
1400fde
Compare
Motivation
This is an extension for setting limited depth for
nix::Value
printing. Sometimes this list is fairly large because of recursive set inside nix, and printing in a desired depth make things much easier for users who just want to see limited depth (for example, when usingnix repl
, we may only want to seedepth = 1
attribute fields, instead of digging into it (basically unreadable). Maybe we can extendnix repl
after this change, for limited depth printing.Context
I'm writting a nix language server which would like to provide consistent developer experience between editors and official nix implementation, and
nix::Value::print
seems a good way to show values (there is no other good public method to do so). And this method may take long time to finish.Related PR: nix-community/nixd#149
Checklist for maintainers
Maintainers: tick if completed or explain if not relevant
tests/**.sh
src/*/tests
tests/nixos/*
Priorities
Add 馃憤 to pull requests you find important.