Skip to content
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

Change default formatter for any language #2362

Closed
lebakasable opened this issue May 1, 2022 · 6 comments · Fixed by #2942
Closed

Change default formatter for any language #2362

lebakasable opened this issue May 1, 2022 · 6 comments · Fixed by #2942
Assignees
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors

Comments

@lebakasable
Copy link

Idea

Adding an option like this:

[[lang]]
name="yeah"
formatter="youhou" // command to execute when formatting instead of the lsp' default 

Why ?

Because, for example, whe CAN'T format any Zig code with ZLS (just an example 😡)

@lebakasable lebakasable added the C-enhancement Category: Improvements label May 1, 2022
@the-mikedavis
Copy link
Member

This needs a bit of design because currently auto-formatting is only done through the language server. We can't just add a configuration for a formatter binary because it would fight with the language server for any language that has a formatter binary and LSP format.

This probably depends on #1125

@kirawi
Copy link
Member

kirawi commented May 1, 2022

Could we disable the formatting request if a binary is defined for formatting?

@kirawi kirawi added the A-helix-term Area: Helix term improvements label May 1, 2022
@lebakasable
Copy link
Author

Yes I think

@slinlee
Copy link
Contributor

slinlee commented May 4, 2022

This would be great for using prettier which I use for most languages it supports. As @David-Else mentioned in #2182 the commands are like prettier --parser json (the parser needs to be manually set when piping the input vs reading from a file)

@thomas-profitt
Copy link

As a workaround, to manually run an external program to reformat the currently-open file in Helix:

  1. % to select everything (or only the part you want to reformat)
  2. | to pipe the selection to an external program's stdin and replace it with the program's stdout,
  3. mix format - (if it's an elixir file, for example)

@kirawi kirawi added E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors labels May 15, 2022
@kirawi
Copy link
Member

kirawi commented May 22, 2022

I think that what we can do is:

  • Add a config option in languages.toml to define a formatter command, and disable LSP formatting requests in Document::format() if a formatter is defined.
  • Send the contents of the buffer to the formatter, and use helix-core::diff::compare_ropes() so we can avoid a problem like Auto-format selects entire document #2404.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-enhancement Category: Improvements E-easy Call for participation: Experience needed to fix: Easy / not much E-good-first-issue Call for participation: Issues suitable for new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants