-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nix pretty-printer/canonicalizer #832
Comments
|
How much of a pain would it be to make it preserve comments? It seems like most ASTs other than these auto-formatters will typically discard comments fairly early on, and might also discard whitespace people intended to keep. For example, the jsonnet canonicalizer will preserve single and double blank lines (under the assumption that the human author added them for a reason), but coalesce 3 or more blank lines into two. |
Currently, comments are discarded already in the lexer. I'm currently thinking about changing that for an other purpose (being able to do more reflection inside nix to be able to generate documentation for functions) |
That sounds awesome for several reasons 👍 |
Ah, this is also currently only idempotent if done twice:
|
https://github.com/Gabriel439/nixfmt is incomplete, but does exactly this. See Gabriella439/nixfmt#3 for the current status |
Would be nice to integrate nixfmt with nix-mode (emacs mode) and nixIdea (intellij's idea plugin). |
Related: #1102. |
What about aiming for the LSP method here? I think there's some works on nix LSP integrations somewhere. That would give benefits for other editors as well. |
https://github.com/domenkozar/hnix-lsp works, but doesn't support comments (yet) |
This now exists https://github.com/justinwoo/format-nix/ but it's performance is quite slow..
Against https://github.com/digital-asset/daml/blob/master/nix/packages.nix |
using a bit modified version of https://github.com/hercules-ci/canonix/ that is not really usable yet - might be after ZuriHac. |
We have https://github.com/nix-community/nixpkgs-fmt now, the main question is if it becomes part of Nix some day. |
I marked this as stale due to inactivity. → More info |
I closed this issue due to inactivity. → More info |
As there's been much progress on
To reproduce, run While I think the eventuall pretty-printing tool should be based on |
Perhaps nixfmt should learn to deal with such strings inside of «» and accept them as pseudo-literals for the purpose of processing Nix output. |
If we can read in the AST and spit it back out again in a standard (ideally somewhat pretty) format, that'd do a reasonable job at this.
Ideally it would preserve comments and such.
The text was updated successfully, but these errors were encountered: