Format .heex on save
woylie opened this issue · 11 comments
The answer might be obvious, but I couldn't figure it out. LiveView 0.17.8 adds a formatter plugin for heex
templates. I configured it and it works fine when I run mix format
. How do I tell LSP-elixir to format .heex
files on save? I know there's the languages
key in the package configuration, which includes the syntaxes. I assume I have to add the HEEx syntax there, but I don't know how to reference it. I'm using the ElixirSyntax package.
Looks like it's not supported by the LS yet.
You can track this issue. elixir-lsp/elixir-ls#660
Well, formatter plugins are not the issue per se. I have configured the Absinthe.Formatter
plugin to format a custom GraphQL sigil. Format on save using the LSP for those sigils in .ex files works just fine.
For .heex files, I'm not seeing the LSP: Format File
option in the command palette, so I think I need to add the syntax to the LSP-elixir configuration, but as I said, I don't know how.
Formatting .ex files with mix format
also formats the HEEx code in the ~H
sigil, but formatting them with the LSP does not, although the rest of the file is still formatted and I'm not seeing any errors.
To activate LSP-elixir on heex files, add this to your LSP-elixir settings:
"selector": "source.elixir, text.html.heex",
Thanks, now I at least see the command. Just doesn't do anything.
Yup. That's where I was at. Then I checked the Elixir-LS project and dicovered that it's not supported yet. :)
The upside is you get error checks on the templates now. You can also add text.html.eex
if you have them.
0.5.0 (with ElixirLS 0.11) might close this issue.
I can format heex files with the command palette now, but it doesn't format them on save. I have this in my LSP-Elixir settings:
{
"settings": {
"elixirLS": {
"dialyzerEnabled": true
}
},
"selector": "source.elixir, text.html.heex"
}
Am I missing something?
https://github.com/sublimelsp/LSP-elixir#format-on-save
{
"lsp_format_on_save": true
}
Format on save is an option that LSP reads from user settings. It's recommended to set it per syntax, in our case we can set this option in elixir syntax specific settings. However, feel free to turn it on for all languages though, in general settings.
.ex
files were already formatted on save without problems, only html.heex
files weren't. After adding the option to the LSP Elixir settings, it seems to work, though.
heex is a separate syntax, though from the same package. might as well set it there. if setting it on the plugin works, sure why not.