Rob1

Rob1

how to configure VSCode to autoformat on save?

Edit: I solved this.

This post is how I solved this problem. It requires installing the extension “run on save” and setting it to run mix format.

I still have ElixirLS installed, the above solution doesn’t interfere with it.

My original post is below.


I’d like to format my code on save (using mix format) in VSCode, I saw that ElixirLS should have this functionality so I set it to do so by putting this in my settings.json:

"[elixir]": {
    "editor.defaultFormatter": "JakeBecker.elixir-ls"
    "editor.formatOnSave": true,
...

However, when I open another file in a project, it says the file “is not included in .formatter.exs” (it’s ElixirLS that shows that message) despite the fact that it has an exs file extension. For some other files format on save works, such as if I open the project_test.exs file change the formating and save it, it gets autoformated correctly.

The .formatter.exs reads:

# Used by "mix format"
[
  inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

Which should catch this file. So I’m at a loss why the file is not being caught. For me it’s important to autoformat my files on save, for consistent formating.

Any ideas? I am on Windows 10.

Steps to reproduce:

1. Install ElixirLS and set it to the default formater for Elixir files as per above.
2. mix new project
3. In the project directory, add an exs file
4. Open it in vscode.
5. When saved it shows this error.

Any ideas?

Most Liked

lud

lud

Elixir LS is supposed to respect the .formatter.exs rules by now. But it does not always work for me either.

Since I run my tests all the time I just added mix format in front of my test command :smiley:

Where Next?

Popular in Questions Top

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
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
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
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
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
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
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
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
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
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
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New

We're in Beta

About us Mission Statement