-
Notifications
You must be signed in to change notification settings - Fork 196
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
Feature Request: Support mix format plugins #660
Comments
confirmed; a formatter plugin will allow for this. |
I may have time to make a PR to add support for this, what has to be done to make it work? |
Super pumped for this! Thanks y'all! |
Anyone know if it works for elixir-ls in Emacs? |
With the recent addition of the LiveView formatter in 0.17.8 I noticed that the formatting does work automatically in VSCode when using .ex files with the
I used the sample code from the elixir formatter docs. test.html.heex: <section><h1> <b><%= @user.name %></b></h1></section> .formatter.exs [
import_deps: [:phoenix],
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{heex,ex,exs}"]
] |
@benvp After upgrading LV, did you run |
@frankdugan3 Yeah I did that. Also deleted the build and deps folder. When running |
@benvp I forgot to mention it, but it also requires Elixir |
I have the exact same situation as @benvp described.
|
I can confirm the same issue. elixir v1.13.4 .formatter.exs
Phoenix LiveView
.ex files with ~H are formatted correctly .heex file returns error
Added inspect for the exception
|
Slightly OT, VSCode instructions For anything to work, you will need a recent Elixir version. I got 1.13.4 running. Also
Then apparently the At least for me this plugin does not work with
However this plugin works for doing the same thing:
You will have to change (or remove, and it will ask) the default formatter in your VSCode "[phoenix-heex]": {
"editor.defaultFormatter": "animus-coop.vscode-elixir-mix-formatter", // Relevant line
"editor.detectIndentation": false,
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.tabSize": 2,
"editor.trimAutoWhitespace": true,
"files.insertFinalNewline": false,
"files.trimTrailingWhitespace": true
}, I hope this helps someone. |
The actual problem (IMHO) is that ElixirLS uses
What can be done here, is to use Mix.Tasks.Formatter.formatter_for_file/2 to format the source file, same as the Would this be a way to go? If this is valid, I might be able to prepare a PR for this. |
* Use formatter_for_file instead of formatter_opts_for_file which is deprecated now * Fallback to original Code.format_string!
* Use formatter_for_file instead of formatter_opts_for_file which is deprecated now * Fallback to original Code.format_string!
* Use formatter_for_file instead of formatter_opts_for_file which is deprecated now * Fallback to original Code.format_string!
Any update on this issue? It looks like the PR #690 is accepted but not merged. Thank you guys for your work on this! |
* Use formatter_for_file instead of formatter_opts_for_file which is deprecated now * Fallback to original Code.format_string! Co-authored-by: Dalibor Horinek <[email protected]>
🥳 🎉 🙇🏻 ❤️ |
Note for others or future me to find. My formatter failed with plugin not found on vscode elixir-ls ONLY. Console worked properly. The issue was that elixir-ls was building as test env. This failed as a result: This obviously works: |
@ddengler You can switch ElixirLS mix env to |
the suggestion of @lukaszsamson worked for me, I had |
Elixir 1.13 added mix format plugins: https://hexdocs.pm/mix/1.13.2/Mix.Tasks.Format.html#module-plugins
ElixirLS should support these plugins if defined in the user's project.
Initially requested in: elixir-lsp/vscode-elixir-ls#224
The text was updated successfully, but these errors were encountered: