Revelry engineering blog header image lightbulb twil this week i learned. Chalkboard style

#RevTWIL: How to Debug Elixir with Visual Studio (VS)

At Revelry, we believe in sharing and learning from one another (beliefs that are rooted in our Core Values). Among the many things we do to encourage internal knowledge exchange is to have a different team member present at each week’s Engineering Meeting. These presentations don’t have to be lengthy, formal, or complicated; in fact, many are brief, but also powerful in that they teach our Revelers something new, inspire conversation, and encourage collaboration.

In the spirit of sharing, we share our This Week I Learned presentations (aka RevTWILs”) here. We hope you find them helpful.

THIS WEEK: Software engineer Sarah Herren shares on how to debug Elixir with VS:

Prerequisites:


Install ElixirLS: Elixir Support & Debugger vs code extension.

Create your launch.json file.
From the debugger panel, select create launch.json file.
If it gives you the option, select mix.

It might need a little help customizing start scripts/options for your project. (I listed what tripped me up in my Gotchas below.)

Configurations:

DEFAULT TASK


{
"type": "mix_task",
"name": "mix (Default task)",
"request": "launch",
"projectDir": "${workspaceRoot}"
},

GOTCHAS
If you use Phoenix server (i.e. start your project w/ mix phx.server), add "task": "phx.server' below the request in your (Default task).

{
      "type": "mix_task",
      "name": "mix (Default task)",
      "request": "launch",
      "task": "phx.server",
      "projectDir": "${workspaceRoot}"
    },

TEST

{
      "type": "mix_task",
      "name": "mix test",
      "request": "launch",
      "task": "test",
      "taskArgs": ["--trace", "${file}"],
      "startApps": true,
      "projectDir": "${workspaceRoot}",
      "requireFiles": []
    }

GOTCHAS
If you are running the configuration for non-Phoenix tests:
Update "startApps": false

EXTRAS
In "requireFiles": You can include only the paths for the tests you’d like to run inside the array.
Or get really slick and add the trace flag in front of an accepted dynamic variable, like file to your "taskArgs" array.
This way, the debugger will be aware of what test file it should run, rather than running everything.

Your config may look different, but here is an example of an updated test config file from a project I’m working on:

{
  "type": "mix_task",
  "name": "mix test",
  "request": "launch",
  "task": "test",
  "taskArgs": ["--trace", "${file}"],
  "startApps": false,
  "projectDir": "${workspaceRoot}",
  "requireFiles": []
}

Just remember to toggle your configuration to mix test before launching the debugger

We're building an AI-powered Product Operations Cloud, leveraging AI in almost every aspect of the software delivery lifecycle. Want to test drive it with us? Join the ProdOps party at ProdOps.ai.