Skip to content

DAP support elixir

Zeioth edited this page Oct 4, 2023 · 2 revisions

Nothing special needs to be done for elixir.

How to setup DAP to debug with elixir

Please note that this section has nothing to do with compiler.nvim. I'm documenting this to make your life easier. To debug elixir with DAP you have to:

  • Install the mason package elixir-ls.
  • :cd your project root before running DAP.
  • Note that on elixir projects, your program code is in ./lib, a dir above that you have the project root.

Here you have an example of how to configure DAP for elixir

local dap = require("dap")

-- Elixir
dap.adapters.mix_task = {
  type = 'executable',
  command = vim.fn.stdpath("data") .. '/mason/bin/elixir-ls-debugger';
  args = {}
}
dap.configurations.elixir = {
  {
    type = "mix_task",
    name = "mix test",
    task = 'test',
    taskArgs = {"--trace"},
    request = "launch",
    startApps = true, -- for Phoenix projects
    projectDir = "${workspaceFolder}",
    requireFiles = {
      "test/**/test_helper.exs",
      "test/**/*_test.exs"
    }
  },
}

How to check if everything works

Just insert a breakpoint, run :DapContinue and you will see something like

screenshot_2023-10-04_20-18-17_317315772

Congratulations, now you can compile and debug elixir.

Important for you to know

  • You don't need to manually compile the program in debug mode before calling DAP. The debug adapter takes care of everything.
  • If you find any issue while configuring DAP, run :DapSetLogLevel trace and :DapShowLog to find the reason.