helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
31.15k stars 2.3k forks source link

set nixfmt as the default formatter for nix #11001

Closed notnmeyer closed 5 days ago

notnmeyer commented 1 week ago

sets the default formatter for nix to nixfmt and enables auto-formatting.

closes https://github.com/helix-editor/helix/issues/10803

poliorcetics commented 1 week ago

Is it stable yet ? I agree that using what is going to be the official formatter is nice but it's still in < 1.0 so I'm afraid they'll do breaking changes yet and we'll get issues with people complaining helix is changing all the formatting because of two different versions of nixfmt on two machines

notnmeyer commented 1 week ago

could they... use nix to avoid that? joking aside, if this a concern a practical solution would just be disable auto-format as a default. i think the scenario where different tooling versions "fight" over the correct formatting style can apply to a lot of tools and different configuration settings. personally, i don't think its that big of deal.

poliorcetics commented 1 week ago

could they... use nix to avoid that

I must admit I laughed 😁

And really my comment was a question for you. I settled on "nixpkgs-fmt" a long time ago for nix formatting because I didn't want to depend on something that, at the time, was still only a project and not actual working code, but if the situation has changed and stabilized, adding out of the box support in helix is certainly something I'll agree with.

I have not followed evolutions though, so I genuinely don't know 😅

notnmeyer commented 1 week ago

the current RFC style is packaged in nixfmt-rfc-style (which still installs a nixfmt binary) and i believe the intention is to eventually just have the nixfmt package be the source of truth. i cant comment on how "stable" the formatter is, but ive been using it myself and it works fine.

the main points here:

  1. the style rfc has been adopted
  2. the formatter is packaged and available
the-mikedavis commented 6 days ago

Yeah let's keep auto-format off for now by default. We should only enable auto-format for languages where formatting is ubiquitous like Rust - otherwise it can unexpectedly reformat older code. Eventually if formatting becomes very popular for Nix we can enable it but where the RFC was accepted recently I think it's too soon.

Super ideally though we wouldn't need to set up a formatter binary for this. Ideally the language servers would depend-on/use nixfmt. External formatters are fairly wasteful since we need to spawn them and send the whole document through them and figure out the diff ourself per-save while with language servers we have incremental document sync and text edits to describe the changes. Maybe for now we could just recommend formatter.command = "nixfmt" in the documentation since I assume language servers will follow the RFC in the (near?) future.

notnmeyer commented 5 days ago

or now we could just recommend formatter.command = "nixfmt" in the documentation

works for me, thanks