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

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
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
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
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
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
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
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

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement