Codball

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

fklement

You could also use the extension emeraldwalk/vscode-runonsave https://github.com/emeraldwalk/vscode-runonsave
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.

14
Post #4
factoryd

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

blatyo

Conduit Core Team

EDIT: This extension is recommended for vscode now: https://marketplace.visualstudio.com/items?itemName=elixir-lsp.elixir-ls

I’d recommend this extension instead: https://marketplace.visualstudio.com/items?itemName=JakeBecker.elixir-ls

It’ll do formatting for you among other things. Also, should be able to detect your .formatter.exs without any config.

belaustegui

belaustegui

Thank you very much for your comment! Although I am currently using ElixirLS, this looks like a fantastic extension and it seems very useful for lots of things :bowing_man:

Where Next?

Popular in Questions Top

freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New

We're in Beta

About us Mission Statement