vscode-elixir-ls
vscode-elixir-ls copied to clipboard
Formatting on save does not work with heex files.
The auto formatter does not work on heex
files, even after setting up the configuration in my project correctly and adding the elixir-ls plugin as the default formatter in settings.json
. If I run a mix format
in the terminal, the heex
files are formatted.
# .formatter.exs
[
import_deps: [:ecto, :phoenix],
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
subdirectories: ["priv/*/migrations"]
]
# settings.json
"[phoenix-heex]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "JakeBecker.elixir-ls"
},
Is this expected? Is it something to implement on the vscode-elixir-ls level?
Environment
- Elixir & Erlang versions (elixir --version): Erlang/OTP 24, Elixir 1.13.4
- VSCode ElixirLS version: 0.9.0
- Operating System Version: macOS Monterey 12.1 (M1)
I have the same issue, error is
[Error - 7:51:17 AM] Request textDocument/formatting failed.
Message: Unable to format due to syntax error
Code: -32603
Just confirmed: latest master version of this repo + latest master of elixir-ls suffers from same issue.
Same for me
Message: Unable to format due to syntax error
Code: -32603
I installed latest elixir 1.13.4 and liveview. Automatic formatting in vscode works great for ~H
sigil, but fails on .heex
files.
I tried formatting from the command line directly the .heex
files and that work ok for me.
Not sure if related, but I noticed in the elixir ls output that it says is using version 0.8.2
Started ElixirLS v0.8.2
Elixir version: "1.13.4 (compiled with Erlang/OTP 22)"
Erlang version: "24"
ElixirLS compiled with Elixir 1.10.4 and erlang 22
But there is not release with that number in the changelog as it jumps from 0.8.1 to 0.9.0 so maybe that is just the latest release
Same for me
Message: Unable to format due to syntax error Code: -32603
I installed latest elixir 1.13.4 and liveview. Automatic formatting in vscode works great for
~H
sigil, but fails on.heex
files. I tried formatting from the command line directly the.heex
files and that work ok for me.Not sure if related, but I noticed in the elixir ls output that it says is using version 0.8.2
Started ElixirLS v0.8.2 Elixir version: "1.13.4 (compiled with Erlang/OTP 22)" Erlang version: "24" ElixirLS compiled with Elixir 1.10.4 and erlang 22
But there is not release with that number in the changelog as it jumps from 0.8.1 to 0.9.0 so maybe that is just the latest release
I see the same version mismatch, but I'm not sure if it matters, even with the custom build (everything bumped to master), where I do see the correct version
Started ElixirLS v0.9.0
Elixir version: "1.13.3 (compiled with Erlang/OTP 24)"
Erlang version: "24"
ElixirLS compiled with Elixir 1.13.4 and erlang 24
it doesn't work.
Yeah, I tried that as well (compiling from master). Error remains
I tried reproducing the error while running the formatter in the command line. I installed with asdf a different elixir version (1.12.0) and then I get a similar syntax error when formatting a .heex
file
mix format failed for file: edit.html.heex
** (SyntaxError) edit.html.heex:1:1: syntax error before: '<'
(elixir 1.12.0) lib/code.ex:978: Code.format_string!/2
(mix 1.12.0) lib/mix/tasks/format.ex:418: Mix.Tasks.Format.format_file/2
(elixir 1.12.0) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
(elixir 1.12.0) lib/task/supervised.ex:35: Task.Supervised.reply/5
(stdlib 3.17.1) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
so maybe is related to the plugin using an older Elixir version, but what I don't get, if that is the case, how it does work on ~H
sigils
As a workaround, you can install the runonsave extension for VSCode and configure that to run mix format
: https://elixirforum.com/t/heex-formatter-a-formatter-for-heex-templates/45649/18?u=nicd
Sadly then "save without formatting" won't work. So it would be nice to get this working with the extension directly.
I wanted to offer an alternative solution that worked for me. I installed another VSCode extension called Elixir Mix Formatter and set this to be my default formatter for elixir and heex files which seems to work as expected.
make sure you have the latest version of Elixir, just run asdf install or brew uprgrade that worked for me
https://github.com/elixir-lsp/elixir-ls/pull/690 just got merged... 🥳
elixir-lsp/elixir-ls#690 just got merged... 🥳
Yeah got this working with the VS Code extension by pulling master
on elixir-ls
and building the extension vscode-elixir-ls
(also on master
) locally against Elixir 1.13.4 and Erlang 25.0.2. No Elixir Mix Formatter needed any longer; just have the one extension, vscode-elixir-ls
, handling everything now.
Edit: to be clear now formats all of .ex, .exs, .heex
utilizing mix format
plugins in .formatter.exs
(in my case Phoenix.LiveView.HTMLFormatter
) via this extension built from source.
Just in case anybody wonders how to compile the current master, try this little snippet:
(Remember to change the version to the current VSCode extension version. Currently v0.11.0
)
git clone --depth 1 --branch master https://github.com/elixir-lsp/elixir-ls.git ~/elixir_ls
cd ~/elixir_ls
mix deps.get
mix elixir_ls.release -o ~/.vscode/extensions/jakebecker.elixir-ls-0.11.0/elixir-ls-release/
For everyone tracking this, note elixir-ls
was updated with version 0.11.0 of the extension, according to elixir-ls/CHANGELOG.md.
Fixed in v0.11