Skip to content

Commit f074633

Browse files
committed
add support for launch with no debug
1 parent 238803b commit f074633

File tree

2 files changed

+118
-16
lines changed

2 files changed

+118
-16
lines changed

apps/elixir_ls_debugger/lib/debugger/server.ex

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ defmodule ElixirLS.Debugger.Server do
183183
end
184184

185185
@impl GenServer
186+
def handle_call(
187+
{:dbg, _binding, %Macro.Env{}, _stacktrace},
188+
_from,
189+
state = %__MODULE__{config: %{"noDebug" => true}}
190+
) do
191+
# auto continue
192+
{:reply, {:ok, false}, state}
193+
end
194+
186195
def handle_call({:dbg, binding, %Macro.Env{} = env, stacktrace}, from, state = %__MODULE__{}) do
187196
{pid, _ref} = from
188197
ref = Process.monitor(pid)
@@ -532,11 +541,7 @@ defmodule ElixirLS.Debugger.Server do
532541
{%{}, state}
533542
end
534543

535-
defp handle_request(launch_req(_, config) = args, state = %__MODULE__{}) do
536-
if args["arguments"]["noDebug"] == true do
537-
Output.debugger_important("launch with no debug is not supported")
538-
end
539-
544+
defp handle_request(launch_req(_, config), state = %__MODULE__{}) do
540545
server = self()
541546

542547
{_, ref} = spawn_monitor(fn -> launch(config, server) end)
@@ -565,6 +570,16 @@ defmodule ElixirLS.Debugger.Server do
565570
{%{}, %{state | config: config}}
566571
end
567572

573+
defp handle_request(
574+
set_breakpoints_req(_, %{"path" => _path}, _breakpoints),
575+
%__MODULE__{config: %{"noDebug" => true}}
576+
) do
577+
raise ServerError,
578+
message: "invalidRequest",
579+
format: "Cannot set breakpoints when running with no debug",
580+
variables: %{}
581+
end
582+
568583
defp handle_request(
569584
set_breakpoints_req(_, %{"path" => path}, breakpoints),
570585
state = %__MODULE__{}
@@ -604,6 +619,16 @@ defmodule ElixirLS.Debugger.Server do
604619
{%{"breakpoints" => breakpoints_json}, state}
605620
end
606621

622+
defp handle_request(
623+
set_function_breakpoints_req(_, _breakpoints),
624+
%__MODULE__{config: %{"noDebug" => true}}
625+
) do
626+
raise ServerError,
627+
message: "invalidRequest",
628+
format: "Cannot set function breakpoints when running with no debug",
629+
variables: %{}
630+
end
631+
607632
defp handle_request(
608633
set_function_breakpoints_req(_, breakpoints),
609634
state = %__MODULE__{}
@@ -653,7 +678,7 @@ defmodule ElixirLS.Debugger.Server do
653678
breaks_after = :int.all_breaks(m)
654679
lines = for {{^m, line}, _} <- breaks_after -- breaks_before, do: line
655680

656-
# pass nil as log_message - not supported on function breakpoints as of DAP 1.51
681+
# pass nil as log_message - not supported on function breakpoints as of DAP 1.63
657682
update_break_condition(m, lines, condition, nil, hit_count)
658683

659684
{:ok, lines}
@@ -706,7 +731,9 @@ defmodule ElixirLS.Debugger.Server do
706731
end
707732

708733
defp handle_request(configuration_done_req(_), state = %__MODULE__{}) do
709-
:int.auto_attach([:break], build_attach_mfa(:breakpoint_reached))
734+
unless state.config["noDebug"] do
735+
:int.auto_attach([:break], build_attach_mfa(:breakpoint_reached))
736+
end
710737

711738
task = state.config["task"]
712739
args = state.config["taskArgs"]
@@ -742,6 +769,16 @@ defmodule ElixirLS.Debugger.Server do
742769
{%{}, state}
743770
end
744771

772+
defp handle_request(
773+
pause_req(_, _thread_id),
774+
%__MODULE__{config: %{"noDebug" => true}}
775+
) do
776+
raise ServerError,
777+
message: "invalidRequest",
778+
format: "Cannot pause process when running with no debug",
779+
variables: %{}
780+
end
781+
745782
defp handle_request(pause_req(_, thread_id), state = %__MODULE__{}) do
746783
pid = state.thread_ids_to_pids[thread_id]
747784

@@ -1365,7 +1402,6 @@ defmodule ElixirLS.Debugger.Server do
13651402
task_args = config["taskArgs"] || []
13661403
auto_interpret_files? = Map.get(config, "debugAutoInterpretAllModules", true)
13671404

1368-
set_stack_trace_mode(config["stackTraceMode"])
13691405
set_env_vars(config["env"])
13701406

13711407
File.cd!(project_dir)
@@ -1427,14 +1463,20 @@ defmodule ElixirLS.Debugger.Server do
14271463
exclude_module_names
14281464
|> Enum.map(&wildcard_module_name_to_pattern/1)
14291465

1430-
if auto_interpret_files? do
1431-
auto_interpret_modules(Mix.Project.build_path(), exclude_module_pattern)
1432-
end
1466+
unless config["noDebug"] do
1467+
set_stack_trace_mode(config["stackTraceMode"])
14331468

1434-
if required_files = config["requireFiles"], do: require_files(required_files)
1469+
if auto_interpret_files? do
1470+
auto_interpret_modules(Mix.Project.build_path(), exclude_module_pattern)
1471+
end
14351472

1436-
if interpret_modules_patterns = config["debugInterpretModulesPatterns"] do
1437-
interpret_specified_modules(interpret_modules_patterns, exclude_module_pattern)
1473+
if required_files = config["requireFiles"], do: require_files(required_files)
1474+
1475+
if interpret_modules_patterns = config["debugInterpretModulesPatterns"] do
1476+
interpret_specified_modules(interpret_modules_patterns, exclude_module_pattern)
1477+
end
1478+
else
1479+
Output.debugger_console("Running without debugging")
14381480
end
14391481

14401482
updated_config = Map.merge(config, %{"task" => task, "taskArgs" => task_args})

apps/elixir_ls_debugger/test/debugger_test.exs

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ defmodule ElixirLS.Debugger.ServerTest do
100100
Server.receive_packet(server, request(1, "disconnect"))
101101
assert_receive(response(_, 1, "disconnect", %{}))
102102
assert_receive({:EXIT, ^server, {:exit_code, 0}})
103-
Process.flag(:trap_exit, false)
104103
end)
104+
after
105+
Process.flag(:trap_exit, false)
105106
end
106107

107108
test "succeeds when initialized", %{server: server} do
@@ -116,8 +117,9 @@ defmodule ElixirLS.Debugger.ServerTest do
116117
Server.receive_packet(server, request(2, "disconnect"))
117118
assert_receive(response(_, 2, "disconnect", %{}))
118119
assert_receive({:EXIT, ^server, {:exit_code, 0}})
119-
Process.flag(:trap_exit, false)
120120
end)
121+
after
122+
Process.flag(:trap_exit, false)
121123
end
122124
end
123125

@@ -312,6 +314,64 @@ defmodule ElixirLS.Debugger.ServerTest do
312314

313315
Server.receive_packet(server, continue_req(15, thread_id))
314316
assert_receive response(_, 15, "continue", %{"allThreadsContinued" => true})
317+
318+
assert_receive(
319+
event(_, "exited", %{
320+
"exitCode" => 0
321+
})
322+
)
323+
324+
assert_receive(event(_, "terminated", %{"restart" => false}))
325+
end)
326+
end
327+
328+
@tag :fixture
329+
test "launch with no debug", %{server: server} do
330+
in_fixture(__DIR__, "mix_project", fn ->
331+
Server.receive_packet(
332+
server,
333+
initialize_req(1, %{
334+
"supportsVariablePaging" => true,
335+
"supportsVariableType" => true
336+
})
337+
)
338+
339+
assert_receive(response(_, 1, "initialize", %{"supportsConfigurationDoneRequest" => true}))
340+
341+
Server.receive_packet(
342+
server,
343+
launch_req(2, %{
344+
"request" => "launch",
345+
"type" => "mix_task",
346+
"noDebug" => true,
347+
"task" => "run",
348+
"taskArgs" => ["-e", "Some.fun_1(2)"],
349+
"projectDir" => File.cwd!()
350+
})
351+
)
352+
353+
assert_receive(response(_, 2, "launch", %{}), 5000)
354+
assert_receive(event(_, "initialized", %{}))
355+
356+
Server.receive_packet(server, request(5, "configurationDone", %{}))
357+
assert_receive(response(_, 5, "configurationDone", %{}))
358+
359+
Server.receive_packet(server, request(6, "threads", %{}))
360+
assert_receive(response(_, 6, "threads", %{"threads" => threads}))
361+
# ensure thread ids are unique
362+
thread_ids = Enum.map(threads, & &1["id"])
363+
assert Enum.count(Enum.uniq(thread_ids)) == Enum.count(thread_ids)
364+
365+
assert_receive(
366+
event(_, "exited", %{
367+
"exitCode" => 0
368+
}),
369+
3000
370+
)
371+
372+
assert_receive(event(_, "terminated", %{"restart" => false}))
373+
end)
374+
end
315375
end)
316376
end
317377

0 commit comments

Comments
 (0)