Codball
Mix format on save VSCode
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an extension called vscode-elixir-formatter. When I save however:
I have a .formatter.exs in my project directory which looks like:
[
import_deps: [:ecto, :phoenix],
inputs: ["mix.exs", "*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
subdirectories: ["priv/*/migrations"]
]
and I’ve checked all the boxes in the VSC user formatter settings. Do I need to tell vscode somehow where my .formatter.exs file is?
Most Liked
fklement
You could also use the extension emeraldwalk/vscode-runonsave GitHub - emeraldwalk/vscode-runonsave: Visual Studio Code extension to run commands whenever a file is saved. · GitHub
And then put the following in your settings.json:
"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\.exs?$",
"isAsync": false,
"cmd": "cd ${workspaceRoot} && mix format ${file}"
}
]
},
This could also be useful for other commands which you want to run automatically on save.
factoryd
I also recommend ElixirLS. But that alone will not format on save; in my experience.
To get that, just add this line to your settings.json:
"editor.formatOnSave": true
blatyo
EDIT: This extension is recommended for vscode now: ElixirLS Fork: DEPRECATED (use original extension) - Visual Studio Marketplace
I’d recommend this extension instead: ElixirLS: Elixir support and debugger - Visual Studio Marketplace
It’ll do formatting for you among other things. Also, should be able to detect your .formatter.exs without any config.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex










