-
-
Notifications
You must be signed in to change notification settings - Fork 350
plugins/conform-nvim: automatically install formatters #3682
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
Conversation
55345a3
to
ab90457
Compare
Almost forgot about this: |
Just found issue #2412 |
ab90457
to
5467761
Compare
cf48224
to
22d3f92
Compare
I've added warnings for packages that do not get installed, they look like this:
I did a small refactor of the I think the code for this looks like a bit of a disaster but it does work and I couldn't come up with a cleaner implementation. It would look better in Haskell with algebraic data types and pattern matching :). |
Just for the record, the generate scripts can technically be in any language. We commonly use bash either at buildtime ( |
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.
Nits, tips, suggestions. Feel free to discuss, dismiss, implement as you see fit.
The overall diff SGTM. Thanks for another great contribution!
Sorry I was unclear; I meant the Nix code for the plugin which obviously is staying Nix. |
7606baa
to
e6e0068
Compare
7cd6e1e
to
09f87f3
Compare
Signed-off-by: saygo-png <[email protected]>
Signed-off-by: saygo-png <[email protected]>
Signed-off-by: saygo-png <[email protected]>
Signed-off-by: saygo-png <[email protected]>
09f87f3
to
401b72a
Compare
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.
LGTM, thanks for another great contribution!
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.
Thanks for doing this, I meant to do it a long time ago!
Seems to work fine for most formatters. For some reason, I get a lua error trying to use ConformInfo
when letting csharpier
get auto installed. But, if I leave my manual configuration of the pkg mapping in formatters.*.command
it is fine.
Would that make for a suitable example (in a followup PR)? |
Auto installation of packages with nix-community/nixvim#3682 so I don't need to maintain EVERY mapping.
Well done @saygo-png! |
@khaneliman The csharpier issue is an upstream issue with conform-nvim stevearc/conform.nvim#699 not this PR |
Looks like someone created a PR for it, too. Thanks for identifying it. stevearc/conform.nvim#772 |
Closes #1141
This PR tries to automatically install the needed packages for Conform formatters.
It extracts formatters names from the
settings.formatters_by_ft
option. Then for each nameit searches for a corresponding package in 4 attribute sets, in order of priority
A user can choose what package a formatter should install, especially useful for versioned formatters like for python 3.12 or 3.13. Since this value can be null, they can also make a formatter not install anything.
The automatic package attrset right now is created with
pkgs.${conform-name}
. More advanced logic could be added, such as replacing all_
with-
and checking if that exists in nixpkgs. But i choose against this since it would only cut down the manual list by a few entries but would add a lot of hard to predict behavior. The current simple defaulting mechanism cuts the manual list in about half.The test right now is very simple. Upstream has each formatter in its own file with a name identical to the Conform name. So I just list that directory of the nix derivation for the plugin, remove
.nix
and generate a Nix list of strings.To prevent IFD this is generated with CI. Then I just create a Nixvim config with every supported formatter in Conform.
Limitations of this approach:
pkgs.foo
. But the formatter expects executablefoofmt
meanwhile the nixpkg does not contain it. This will not be caught as an error in the test.pkgs.foo
AND contains an executable with the same name, but it actually is a totally different executable and package, just with incidentally matching names.I think one could write a more extensive test that covers 1 using Lua but i'm not good enough with Lua to do that.
There is no test for the override functionality or one that checks if custom formatters' packages are getting set to
null
This is because I have no clue how to write that. I'd have to eval those options first, read them, and assert that some predicates hold. For example for the nulling i'd imagine I would read the
customFormatters
attrset, get the values withlib.attrValues
and assert that everything is null. If someone could point me to how to achieve that I could write those tests.