Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve debugger stability #457

Merged
merged 13 commits into from
Jan 14, 2021
1 change: 1 addition & 0 deletions apps/elixir_ls_debugger/lib/debugger/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule ElixirLS.Debugger.CLI do
WireProtocol.intercept_output(&Output.print/1, &Output.print_err/1)
Launch.start_mix()
{:ok, _} = Application.ensure_all_started(:elixir_ls_debugger, :permanent)

IO.puts("Started ElixirLS debugger v#{Launch.debugger_version()}")
Launch.print_versions()
Launch.limit_num_schedulers()
Expand Down
39 changes: 20 additions & 19 deletions apps/elixir_ls_debugger/lib/debugger/output.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule ElixirLS.Debugger.Output do
are sent with sequence numbers that are unique and sequential, and includes client functions for
sending these messages.
"""
import ElixirLS.Utils.WireProtocol, only: [send: 1]
alias ElixirLS.Utils.WireProtocol
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 💯

use GenServer
use ElixirLS.Debugger.Protocol

Expand All @@ -29,12 +29,12 @@ defmodule ElixirLS.Debugger.Output do
GenServer.call(server, {:send_event, event, body})
end

def print(server \\ __MODULE__, str) do
send_event(server, "output", %{"category" => "stdout", "output" => to_string(str)})
def print(server \\ __MODULE__, str) when is_binary(str) do
send_event(server, "output", %{"category" => "stdout", "output" => str})
end

def print_err(server \\ __MODULE__, str) do
send_event(server, "output", %{"category" => "stderr", "output" => to_string(str)})
def print_err(server \\ __MODULE__, str) when is_binary(str) do
send_event(server, "output", %{"category" => "stderr", "output" => str})
end

## Server callbacks
Expand All @@ -46,27 +46,28 @@ defmodule ElixirLS.Debugger.Output do

@impl GenServer
def handle_call({:send_response, request_packet, body}, _from, seq) do
send(response(seq, request_packet["seq"], request_packet["command"], body))
{:reply, :ok, seq + 1}
res = WireProtocol.send(response(seq, request_packet["seq"], request_packet["command"], body))
{:reply, res, seq + 1}
end

def handle_call({:send_error_response, request_packet, message, format, variables}, _from, seq) do
send(
error_response(
seq,
request_packet["seq"],
request_packet["command"],
message,
format,
variables
res =
WireProtocol.send(
error_response(
seq,
request_packet["seq"],
request_packet["command"],
message,
format,
variables
)
)
)

{:reply, :ok, seq + 1}
{:reply, res, seq + 1}
end

def handle_call({:send_event, event, body}, _from, seq) do
send(event(seq, event, body))
{:reply, :ok, seq + 1}
res = WireProtocol.send(event(seq, event, body))
{:reply, res, seq + 1}
end
end
Loading