kidp330

kidp330

I’m trying to run a script with Mix.install inside, and set some breakpoints. I’m running VSCode with the ElixirLS extension. I can run the script just fine if I mix run --no-mix-exs file.exs but not with the debugger, even If I add the flag to taskArgs. Haven’t found this functionality doccumented in the extension docs so either I’m doing something wrong or it’s not implemented?

Showing Posts 1 to 3

sodapopcan

sodapopcan

I don’t have a direct solution but figured I’d respond since you haven’t gotten any bites yet.

By debugger do you mean dbg? If so then I’m not sure this is possible since in order for it to be available, you need to add :runtime_tools to :extra_applications in a mix file. I’m sorry I don’t know the answer but maybe that’s a good enough clue?

…and welcome to Elixir Forum! :slight_smile:

lukaszsamson

lukaszsamson

ElixirLS Core Team

By debugger do you mean dbg

No @sodapopcan, OP means ElixirLS debug adapter (GitHub - elixir-lsp/vscode-elixir-ls: Elixir language support and debugger for VS Code, powered by ElixirLS. · GitHub)

Haven’t found this functionality doccumented in the extension docs so either I’m doing something wrong or it’s not implemented?

@kidp330 ElixirLS debug adapter currently requires a mix project (I opened Debug adapter does not support no mixfile projects · Issue #1037 · elixir-lsp/elixir-ls · GitHub for tracking). Trying to run in a folder that does not contain mix.exs will raise Mix.NoMixProjectError. You can create a dummy project and run your scripts from there.

However this is tricky in case of .exs files.

  1. OTP debugger which ElixirLS uses underneath requires modules to be interpreted before you can set breakpoints in them. So you need to put your code in module functions
  2. .exs files are compiled in memory. To interpret them you need to include them in requireFiles so they are purged, recompiled and their beam files saved to disk so the OTP debugger can interpret them
  3. .exs script starts executing when you compile it not giving the debugger required time to interpret and set breakpoints. It’s not possible to purge a module when a process executes it’s code. The reasult is that interpretation happens when the script has already returned. You can overcome this with invoking your code in a separate process started from the script
  4. mix run exits when the script return. By default debugger will end the session when mix task finishes. You need to set exitAfterTaskReturns to false so the debug session will continue

I was able to create a proof of concept. The debugger breaks when the breakpoint in Abc.debug_me is hit from the task I start. I needed to add some delay though. Otherwise the code finished before the breakpoint was set.

poc.exs

defmodule Abc do
  def debug_me() do
    a = [1, 2, 3]
    b = Enum.map(a, & &1 + 1)
    b
  end
end

a = [1, 2, 3]
b = Enum.map(a, & &1 + 1)
IO.puts("done #{inspect(b)}, #{Abc.debug_me()}")

Task.start(fn ->
  Process.sleep(4000)
  IO.puts("done from task #{inspect(b)}, #{Abc.debug_me()}")
end)

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "mix_task",
      "name": "mix run",
      "request": "launch",
      "task": "run",
      "taskArgs": [
        "--no-mix-exs",
        "poc.exs"
      ],
      "startApps": false,
      "projectDir": "${workspaceRoot}",
      "exitAfterTaskReturns": false,
      "requireFiles": [
        "poc.exs"
      ]
    }
  ]
}

The other possibility is breaking on Kernel.dbg macro. This is easier to achieve. In this case do not put the script into requireFiles as recompilation and interpreting will deadlock the debugger

lukaszsamson

lukaszsamson

ElixirLS Core Team

ElixirLS Debug adapter will support --no-mix-exs in 0.19 release

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews