Skip to content

Commit 8fb2b11

Browse files
committed
implement source DAP request
1 parent b19b8ce commit 8fb2b11

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

apps/debug_adapter/lib/debug_adapter/protocol.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ defmodule ElixirLS.DebugAdapter.Protocol do
3838
end
3939
end
4040

41+
defmacro source_req(seq, args) do
42+
quote do
43+
request(unquote(seq), "source", unquote(args))
44+
end
45+
end
46+
4147
defmacro set_breakpoints_req(seq, source, breakpoints) do
4248
quote do
4349
request(unquote(seq), "setBreakpoints", %{

apps/debug_adapter/lib/debug_adapter/server.ex

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,24 @@ defmodule ElixirLS.DebugAdapter.Server do
885885
{%{}, %{state | config: config}}
886886
end
887887

888+
defp handle_request(
889+
source_req(_, args),
890+
state = %__MODULE__{}
891+
) do
892+
path = args["source"]["path"]
893+
894+
content =
895+
if path == "replinput" do
896+
# this is a special path that VSCode uses for debugger console
897+
# return an empty string as we do not need anything there
898+
""
899+
else
900+
File.read!(path)
901+
end
902+
903+
{%{"content" => content}, state}
904+
end
905+
888906
defp handle_request(
889907
set_breakpoints_req(_, %{"path" => _path}, _breakpoints),
890908
%__MODULE__{config: %{"noDebug" => true}}

apps/debug_adapter/test/debugger_test.exs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3865,4 +3865,43 @@ defmodule ElixirLS.DebugAdapter.ServerTest do
38653865
assert Process.alive?(server)
38663866
end)
38673867
end
3868+
3869+
test "source", %{server: server} do
3870+
in_fixture(__DIR__, "mix_project", fn ->
3871+
Server.receive_packet(server, initialize_req(1, %{}))
3872+
assert_receive(response(_, 1, "initialize", _))
3873+
3874+
Server.receive_packet(
3875+
server,
3876+
%{
3877+
"arguments" => %{
3878+
"sourceReference" => 0,
3879+
"source" => %{"path" => "lib/crash.ex"}
3880+
},
3881+
"command" => "source",
3882+
"seq" => 1,
3883+
"type" => "request"
3884+
}
3885+
)
3886+
3887+
assert_receive(%{"body" => %{"content" => "defmodule MixProject.Crash do" <> _}}, 10000)
3888+
3889+
Server.receive_packet(
3890+
server,
3891+
%{
3892+
"arguments" => %{
3893+
"sourceReference" => 0,
3894+
"source" => %{"path" => "replinput"}
3895+
},
3896+
"command" => "source",
3897+
"seq" => 1,
3898+
"type" => "request"
3899+
}
3900+
)
3901+
3902+
assert_receive(%{"body" => %{"content" => ""}}, 10000)
3903+
3904+
assert Process.alive?(server)
3905+
end)
3906+
end
38683907
end

0 commit comments

Comments
 (0)