# Problem with formatting elixir in vs code

**URL:** <https://forum.elixirforum.com/t/problem-with-formatting-elixir-in-vs-code/52398>\
**Category:** Questions\
**Tags:** troubleshooting, learning-elixir\
**Created:** [December 10, 2022, 10:02am UTC](https://forum.elixirforum.com/t/problem-with-formatting-elixir-in-vs-code/52398 "2022-12-10T10:02:05Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haogudu](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/h/b2d939/32.png) [@Haogudu](https://forum.elixirforum.com/u/Haogudu)\
**Post date:** [December 10, 2022, 10:02am UTC](https://forum.elixirforum.com/t/problem-with-formatting-elixir-in-vs-code/52398/1 "2022-12-10T10:02:05Z")

</div>

Hello, I just started to learn elixir by following Alchemist Camp’s tutorial. And I had problem with formatting my code in vs code editor. I tried multiple formatter extensions. None of them worked for me. And the editor ran into compatibility problem. So, I deleted all the elixir related extension except ElixirLS. The editor finally stop giving me error. But it did not format my code either. Then I checked the “settings.json” file and updated the Elixir part as following:

> “[elixir]”: {  
> “editor.defaultFormatter”: “JakeBecker.elixir-ls”  
> }

I tried to format it again after I reload vs code. It is not working still. Can someone help me with the format setting?

---

<div class="post-metadata">

**Author:** ![bdarla](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bdarla/32/19471_2.png) [@bdarla](https://forum.elixirforum.com/u/bdarla)\
**Post date:** [December 10, 2022, 12:32pm UTC](https://forum.elixirforum.com/t/problem-with-formatting-elixir-in-vs-code/52398/2 "2022-12-10T12:32:09Z")

</div>

You may find some configurations in a related thread:  
[https://forum.elixirforum.com/t/how-can-i-start-using-the-new-heex-formatter-in-vs-code/51420/1](https://forum.elixirforum.com/t/how-can-i-start-using-the-new-heex-formatter-in-vs-code/51420/1)

The one I posted there works fine for me.

---

<div class="post-metadata">

**Author:** ![Haogudu](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/h/b2d939/32.png) [@Haogudu](https://forum.elixirforum.com/u/Haogudu)\
**Post date:** [December 10, 2022, 12:44pm UTC](https://forum.elixirforum.com/t/problem-with-formatting-elixir-in-vs-code/52398/3 "2022-12-10T12:44:29Z")

</div>

The editor reports “Mix Formatter: Failed to format the document” with “Source: Elixir Mix Formatter(Extension)” when I try to format my code.

---

<div class="post-metadata">

**Author:** ![bdarla](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bdarla/32/19471_2.png) [@bdarla](https://forum.elixirforum.com/u/bdarla)\
**Post date:** [December 10, 2022, 1:26pm UTC](https://forum.elixirforum.com/t/problem-with-formatting-elixir-in-vs-code/52398/4 "2022-12-10T13:26:10Z")

</div>

I am not sure that I can deduct the root cause of this problem by the provided error. Is there any chance that you have not installed the relevant plugins?

---

<div class="post-metadata">

**Author:** ![benwilson512](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benwilson512/32/1457_2.png) [@benwilson512](https://forum.elixirforum.com/u/benwilson512)\
**Post date:** [December 10, 2022, 3:44pm UTC](https://forum.elixirforum.com/t/problem-with-formatting-elixir-in-vs-code/52398/5 "2022-12-10T15:44:53Z")

</div>

Hi @Haogudu I believe you are not configuring the right extension. You should be using [GitHub - elixir-lsp/elixir-ls: A frontend-independent IDE "smartness" server for Elixir. Implements the "Language Server Protocol" standard and provides debugger support via the "Debug Adapter Protocol" · GitHub](https://github.com/elixir-lsp/elixir-ls). The JackeBecker.elixir-ls is not the one to use.

---

<div class="post-metadata">

**Author:** ![KristerV](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/kristerv/32/13808_2.png) [@KristerV](https://forum.elixirforum.com/u/KristerV)\
**Post date:** [December 10, 2022, 3:47pm UTC](https://forum.elixirforum.com/t/problem-with-formatting-elixir-in-vs-code/52398/6 "2022-12-10T15:47:24Z")

</div>

i actually haven’t been able to get any formatters to work properly. so i made a “stupid” solution.

I use the [Run on Save](https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave) extension to run `mix format` as it would in Bash (CLI). then all you need to do is make sure `mix format` actually works by using it in Bash.

---

<div class="post-metadata">

**Author:** ![Haogudu](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/h/b2d939/32.png) [@Haogudu](https://forum.elixirforum.com/u/Haogudu)\
**Post date:** [December 10, 2022, 4:02pm UTC](https://forum.elixirforum.com/t/problem-with-formatting-elixir-in-vs-code/52398/7 "2022-12-10T16:02:41Z")

</div>

Hi, @benwilson512 I have followed the link you post. It shows that I have already installed it. I uninstalled all the elixir extension and reinstalled the one in your link. Then I got a message “No mixfile found in project. To use a subdirectory, set `elixirLS.projectDir` in your settings” with “Source: ElixirLS: Elixir support and debugger(Extension)”. I have also tried @bdarla 's setting. Nothing works so far…

---

<div class="post-metadata">

**Author:** ![benwilson512](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benwilson512/32/1457_2.png) [@benwilson512](https://forum.elixirforum.com/u/benwilson512)\
**Post date:** [December 10, 2022, 4:13pm UTC](https://forum.elixirforum.com/t/problem-with-formatting-elixir-in-vs-code/52398/8 "2022-12-10T16:13:41Z")

</div>

Hi @Haogudu can you show the project that you have?

---

<div class="post-metadata">

**Author:** ![Haogudu](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/h/b2d939/32.png) [@Haogudu](https://forum.elixirforum.com/u/Haogudu)\
**Post date:** [December 10, 2022, 4:36pm UTC](https://forum.elixirforum.com/t/problem-with-formatting-elixir-in-vs-code/52398/9 "2022-12-10T16:36:08Z")

</div>

My project folder only has a ex file with a few line of code. In its parent folder, I found a folder called “.elixir\_ls” containing four files “.gitignore”, “calls.dets”, “modules.dets” and “tracer\_db.manifest”. I am not sure if they are related to the issue I am having.

---

<div class="post-metadata">

**Author:** ![bdarla](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bdarla/32/19471_2.png) [@bdarla](https://forum.elixirforum.com/u/bdarla)\
**Post date:** [December 10, 2022, 5:44pm UTC](https://forum.elixirforum.com/t/problem-with-formatting-elixir-in-vs-code/52398/10 "2022-12-10T17:44:58Z")

</div>

Do you have a file “.formatter.exs” with content such as the following?

```elixir
[
  import_deps: [:ecto, :ecto_sql, :phoenix],
  subdirectories: ["priv/*/migrations"],
  plugins: [Phoenix.LiveView.HTMLFormatter],
  inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
]

```

---

<div class="post-metadata">

**Author:** ![benwilson512](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/benwilson512/32/1457_2.png) [@benwilson512](https://forum.elixirforum.com/u/benwilson512)\
**Post date:** [December 10, 2022, 6:24pm UTC](https://forum.elixirforum.com/t/problem-with-formatting-elixir-in-vs-code/52398/11 "2022-12-10T18:24:07Z")

</div>

It is yeah, Elixir LS expects a full mix project generally, it isn’t designed to work with just a handful of EX files.

---

<div class="post-metadata">

**Author:** ![lukaszsamson](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lukaszsamson/32/7671_2.png) [@lukaszsamson](https://forum.elixirforum.com/u/lukaszsamson)\
**Post date:** [October 8, 2023, 12:49pm UTC](https://forum.elixirforum.com/t/problem-with-formatting-elixir-in-vs-code/52398/12 "2023-10-08T12:49:36Z")

</div>

It has some basic support for single files and dirs with no mix project but full feature set works only in mix projects

---

<div class="post-metadata">

**Author:** ![lukaszsamson](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lukaszsamson/32/7671_2.png) [@lukaszsamson](https://forum.elixirforum.com/u/lukaszsamson)\
**Post date:** [October 8, 2023, 1:18pm UTC](https://forum.elixirforum.com/t/problem-with-formatting-elixir-in-vs-code/52398/13 "2023-10-08T13:18:12Z")

</div>

This is incorrect. The vscode extension is still using the original name. Unfortunately it’s not possible to rename a published extension. This is still a correct formatter config for ElixirLS config

```elixir
"[elixir]": {
    "editor.defaultFormatter": "JakeBecker.elixir-ls"
  }

```
