Start Phoenix within Visual Studio Code

@mandarvaze that looks really cool, I’m excited to check that out!!

1 Like

I have Windows 10 running in bootcamp on my Macbook, so I switched over and got set up to try the debugger in the windows environment.

I used the same configuration from above, and I got the debugger to run on a fresh mix phx.new my_app test run.

Since I can’t replicate with the closest thing I’ve got to your environment, here’s a couple of things to play around with to see if they make any difference:

  1. Upgrade to the most recent Elixir and Erlang versions
  2. Get the latest version of Phoenix
  3. Make sure you’ve got the most recent version of Node installed
  4. Try uninstalling and reinstalling ElixirLS. If you’ve got any Elixir specific settings configured in your settings.json, you could try removing them
  5. If you have access to another computer lying around somewhere, try doing a fresh install of Erlang, Elixir, Phoenix, Node, Postgres, VS Code and ElixirLS and see if you can get the debugger working. Sometimes getting something working in another environment gives clarity to what isn’t configured properly in your main one.

Best of luck, the effort is totally worth it to have tools to introspect your variables while the code is running! I came from a .NET development background before I came to Elixir, and the only things I’ve missed are Visual Studio’s phenomenal C# debugger and the world-class Intellisense. ElixirLS is the best we’ve got in the IDE space for those things that I’ve found and I would love to see more adoption so that as a community we can keep improving those tools!

@damonjanis Looking forward to your feedback

work for me. thx
ubuntu 18.04 vs code 1.44.2

After finding all the solution, I tried to add launch.json and tasks.json in my phoenix project. There I can debug in both phoenix server and mix test.

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "mix_task",
      "name": "mix phx.server",
      "task": "phx.server",
      "taskArgs": [],
      "request": "launch",
      "projectDir": "${workspaceRoot}",
      "env": {
        "CLIENT_ID": "12345",
        "CLIENT_SECRET": "54321"
      },
      "excludeModules": ["Argon2.Base"],
      "preLaunchTask": "deps.compile"
    },
    {
      "type": "mix_task",
      "name": "mix test",
      "request": "launch",
      "task": "test",
      "taskArgs": ["--trace"],
      "excludeModules": ["Argon2.Base"],
      "startApps": true,
      "projectDir": "${workspaceRoot}",
      "requireFiles": ["test/**/test_helper.exs", "test/**/*_test.exs"]
    }
  ]
}

tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "test",
      "type": "shell",
      "command": "mix test",
      "group": "test"
    },
    {
      "label": "deps.compile",
      "type": "shell",
      "command": "mix deps.get && mix deps.compile",
      "group": "build"
    }
  ]
}

Do let me know If you found any issue here :slight_smile:

1 Like

That works for me on linux mint:

{
    // Use IntelliSense para saber los atributos posibles.
    // Mantenga el puntero para ver las descripciones de los existentes atributos.
    // Para más información, visite: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "mix_task",
            "name": "iex -S mix",
            "task": "phx.server",
            "request": "launch",
            "projectDir": "${workspaceRoot}"
        },
        {
            "type": "mix_task",
            "name": "mix test",
            "request": "launch",
            "task": "test",
            "taskArgs": [
                "--trace"
            ],
            "startApps": true,
            "projectDir": "${workspaceRoot}",
            "requireFiles": [
                "test/**/test_helper.exs",
                "test/**/*_test.exs"
            ]
        }
    ]
}