JakeBecker / elixir-ls

A frontend-independent IDE "smartness" server for Elixir. Implements the JSON-based "Language Server Protocol" standard and provides debugger support via VS Code's debugger protocol.
Apache License 2.0
843 stars 52 forks source link

ElixirLS debugger unexpectedly stops when used with Phoenix and VSCode #185

Closed rickythefox closed 4 years ago

rickythefox commented 5 years ago

Trying to debug my Phoenix project in VSCode using ElixirLS. The launch config is defined as

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

The debugger starts and displays call stack for a fraction of a second but then immediately stops after "[info] Access TestAppWeb.Endpoint at http://localhost:4000". Has anyone gotten this to work?

Demo: https://i.stack.imgur.com/VMrkG.gif

Erlang/OTP 22 [erts-10.4.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace] Elixir 1.9.1 (compiled with Erlang/OTP 22)

h8 commented 5 years ago

Experiencing exactly the same issues. Looks like it's not related to Phoenix, because I see the same behavior with just mix run command.

jhberges commented 5 years ago

I have a somewhat similar behavior, though the debugger dies with the following error message in my case:

Started ElixirLS debugger
Elixir version: "1.9.1 (compiled with Erlang/OTP 21)"
Erlang version: "22"

13:23:04.326 [info]  Application debugger exited: ElixirLS.Debugger.start(:normal, []) returned an error: shutdown: failed to start child: ElixirLS.Debugger.Server
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function :int.start/0 is undefined (module :int is not available)
            :int.start()
            (debugger) lib/debugger/server.ex:56: ElixirLS.Debugger.Server.init/1
            (stdlib) gen_server.erl:374: :gen_server.init_it/2
            (stdlib) gen_server.erl:342: :gen_server.init_it/6
            (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
lukaszsamson commented 5 years ago

Have you tried disabling phoenix live reload? It's recompiling modules on the fly and my guess is it's interfering with the debugger.

h8 commented 5 years ago

Have you tried disabling phoenix live reload? It's recompiling modules on the fly and my guess is it's interfering with the debugger.

I'm not using Phoenix at all, and no live reload of any kind, and the issue is still present.

jhberges commented 5 years ago

Have you tried disabling phoenix live reload? It's recompiling modules on the fly and my guess is it's interfering with the debugger.

I am using Phoenix in this project, but only as a pure JSON api.

Disabling the live reloading changed nothing - but thanks for the suggestion.

mattraykowski commented 5 years ago

Environments:

Steps to repeat:

  1. mix phx.new vscode_test
  2. cd vscode_test
  3. mix deps.get
  4. mix compile
  5. mix test - Just to verify the tests run normally.
  6. code .
  7. Click Debugger
  8. Click Settings and choose Mix Task
  9. Click Settings again and add:
    {
      "type": "mix_task",
      "name": "mix phx.server",
      "request": "launch",
      "projectDir": "${workspaceRoot}",
      "task": "phx.server"
    },
  10. Choose mix phx.server from dropdown and click the Debug/play icon.
  11. Observe it telling you that Phoenix is running but it is not.
jhberges commented 5 years ago

Well, well, well.

Turns out my variant of the issue was the Ubuntu packaging. The debugger had gone missing in an Erlang/OTP upgrade.

sudo apt install erlang-debugger was my friend, at least. :+1:

rickythefox commented 5 years ago

Well, well, well.

Turns out my variant of the issue was the Ubuntu packaging. The debugger had gone missing in an Erlang/OTP upgrade.

sudo apt install erlang-debugger was my friend, at least. 👍

For me erl -s debugger start launches the debugger, so that's probably not the issue here.

jhberges commented 5 years ago

I spoke too soon, it would seem. Got distracted and didn't get back to this debugging until now, and now I find my self with https://github.com/JakeBecker/vscode-elixir-ls/issues/120, then the debugger abruptly terminating.

Side note: this is an API Phoenix project, using the Commanded framework. Ubuntu 19.04 on a Thinkpad T470s, everything up to date.

Started ElixirLS debugger
Elixir version: "1.9.1 (compiled with Erlang/OTP 21)"
Erlang version: "22"
[debug] Attempting to start Postgrex
[debug] Successfully started Postgrex (#PID<0.325.0>)
[debug] Attempting to start Postgrex.Notifications
[debug] Successfully started Postgrex.Notifications (#PID<0.336.0>)
[debug] Attempting to start Postgrex
[debug] Successfully started Postgrex (#PID<0.338.0>)
[debug] Subscription "XXXX"@"$all" attempting to connect subscriber #PID<0.428.0>
[debug] Subscription "XXXX"@"$all" attempting to connect subscriber #PID<0.427.0>
[debug] Subscription "XXXX"@"$all" catching-up
[debug] XXXX has successfully subscribed to event store
[debug] Subscription "XXXX"@"$all" catching-up
[debug] XXXX  has successfully subscribed to event store
(a bit of a pause, while the debugger is in starting up mode)
[error] 'File operation error: eacces. Target: /root/deb/elixir_1.9.1-1/lib/elixir/lib/collectable.ex. Function: read_file_info. '
[error] 'File operation error: eacces. Target: /root/deb/elixir_1.9.1-1/lib/elixir/lib/enum.ex. Function: read_file_info. '
[error] 'File operation error: eacces. Target: /root/deb/elixir_1.9.1-1/lib/iex/lib/iex/info.ex. Function: read_file_info. '
[error] 'File operation error: eacces. Target: /root/deb/elixir_1.9.1-1/lib/elixir/lib/inspect.ex. Function: read_file_info. '
[error] 'File operation error: eacces. Target: /root/deb/elixir_1.9.1-1/lib/elixir/lib/list/chars.ex. Function: read_file_info. '
[error] 'File operation error: eacces. Target: /root/deb/elixir_1.9.1-1/lib/elixir/lib/string/chars.ex. Function: read_file_info. '
bfcns commented 5 years ago

same problem here... for the eacces error you can use asdf version of erlang/elixir...

but that does not help with the main problem of this thread.

jhberges commented 5 years ago

@phpcitizen nope - just an observation in case it somehow was related. (though the env-var tricks do not seem to work for me)

Another observation is that Cowboy seems to never start. Starting on the command line Cowboy logs infomessages just after Postgrex. In the elixirls console in vscode, those log messages are never logged:

[info] Running xxx.Endpoint with cowboy 2.6.3 at 0.0.0.0:4000 (http)
[info] Access xxx.Endpoint at http://localhost:4000
huangjimmy commented 5 years ago

I experience the same too! Hope this issue be resolved soon

axelson commented 4 years ago

I just published version 0.2.28 of the ElixirLS fork that solves this issue: https://github.com/elixir-lsp/elixir-ls

apostrophedottilde commented 4 years ago

Well, well, well.

Turns out my variant of the issue was the Ubuntu packaging. The debugger had gone missing in an Erlang/OTP upgrade.

sudo apt install erlang-debugger was my friend, at least. 👍

Thanks! This reminded me that I "upgraded" my macos to Catalina yesterday. I reinstall erlang and elixir and it's all working again and I can debug. :)

dealloc commented 4 years ago

@axelson any chance you can PR against this plugin to get this one working again?

axelson commented 4 years ago

@dealloc A PR hasn't been merged in this repo since march of last year (not including the license PR) so I doubt a PR that I made would be merged.

dealloc commented 4 years ago

@axelson Ah yes I see, that's rather unfortunate. I installed the fork for now :)

JakeBecker commented 4 years ago

This project has moved!

It's now being maintained by proactive volunteers from the Elixir community over at elixir-lsp/elixir-ls. Updates will continue to be published from that repo to the original VS Code extension, so no need to switch plugins if you're using VS Code.

To avoid inundating the new maintainers with issues, please verify that your issue persists with the latest version of the extension (which is published from the new repo) before re-filing your issue there.

Thanks for using ElixirLS!