helix-editor / helix

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

Prefer language server formatting to external formatters #9543

Open the-mikedavis opened 9 months ago

the-mikedavis commented 9 months ago

Auto-formatting currently prefers external formatters to language servers:

https://github.com/helix-editor/helix/blob/0975d9c5e7e4caf08d1c1204f09ab6d2f718105d/helix-view/src/document.rs#L725-L815

But I believe this should be reversed: the language server is probably more efficient than us shelling out to the formatter and computing the diff ourselves.

If one wants to prefer the formatter to the language server formatting they can turn off the formatting feature for that language server using only-features / except-features (https://docs.helix-editor.com/languages.html#configuring-language-servers-for-a-language).

David-Else commented 9 months ago

The assumption at the moment is if you have installed an external formatter it is because you want to use it rather than the language server. That does make sense, and therefor this is a big change.

If you make it the default to prefer the language server formatter regardless, then it would also make sense to load up the defaults with all the best external formatters too, then people could easily choose between them by adding the except-features to choose the external. For example, as a default, adding Prettier as an external formatter for all the languages it can handle.

janos-r commented 2 months ago

In languages.toml, if I specify a formatter, than I obviously expect it to apply immediately, and not only after also looking up and specifying the default LSP and disabling it's formatter.