Skip to content

Commit 84b2b2d

Browse files
committed
do not try to load config and compile when mix task args include --no-mix-exs
Fixes #1037
1 parent 10cba4b commit 84b2b2d

File tree

3 files changed

+142
-2
lines changed

3 files changed

+142
-2
lines changed

apps/debug_adapter/lib/debug_adapter/server.ex

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,12 +1724,15 @@ defmodule ElixirLS.DebugAdapter.Server do
17241724
Output.debugger_console("Running with MIX_ENV: #{Mix.env()} MIX_TARGET: #{Mix.target()}\n")
17251725

17261726
Launch.ensure_no_slashes(task)
1727-
Mix.Task.run("loadconfig")
1727+
1728+
unless "--no-mix-exs" in task_args do
1729+
Mix.Task.run("loadconfig")
1730+
end
17281731

17291732
# make sure ANSI is disabled
17301733
Application.put_env(:elixir, :ansi_enabled, false)
17311734

1732-
unless "--no-compile" in task_args do
1735+
unless "--no-compile" in task_args or "--no-mix-exs" in task_args do
17331736
case Mix.Task.run("compile", ["--ignore-module-conflict", "--return-errors"]) do
17341737
{:error, diagnostics} ->
17351738
message =

apps/debug_adapter/test/debugger_test.exs

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,127 @@ defmodule ElixirLS.DebugAdapter.ServerTest do
355355
end)
356356
end
357357

358+
@tag :fixture
359+
test "no mix exs", %{server: server} do
360+
in_fixture(__DIR__, "no_mix_exs", fn ->
361+
Server.receive_packet(
362+
server,
363+
initialize_req(1, %{
364+
"supportsVariablePaging" => true,
365+
"supportsVariableType" => true
366+
})
367+
)
368+
369+
assert_receive(response(_, 1, "initialize", %{"supportsConfigurationDoneRequest" => true}))
370+
371+
Server.receive_packet(
372+
server,
373+
launch_req(2, %{
374+
"request" => "launch",
375+
"type" => "mix_task",
376+
"task" => "run",
377+
"taskArgs" => ["--no-mix-exs", "script.exs"],
378+
"projectDir" => File.cwd!(),
379+
"exitAfterTaskReturns" => false,
380+
"requireFiles" => [
381+
"script.exs"
382+
]
383+
})
384+
)
385+
386+
assert_receive(response(_, 2, "launch", %{}), 5000)
387+
assert_receive(event(_, "initialized", %{}))
388+
abs_path = Path.absname("script.exs")
389+
390+
Server.receive_packet(
391+
server,
392+
set_breakpoints_req(3, %{"path" => abs_path}, [%{"line" => 4}])
393+
)
394+
395+
assert_receive(
396+
response(_, 3, "setBreakpoints", %{"breakpoints" => [%{"verified" => true}]}),
397+
5000
398+
)
399+
400+
Server.receive_packet(server, request(5, "configurationDone", %{}))
401+
assert_receive(response(_, 5, "configurationDone", %{}))
402+
403+
Server.receive_packet(server, request(6, "threads", %{}))
404+
assert_receive(response(_, 6, "threads", %{"threads" => threads}))
405+
# ensure thread ids are unique
406+
thread_ids = Enum.map(threads, & &1["id"])
407+
assert Enum.count(Enum.uniq(thread_ids)) == Enum.count(thread_ids)
408+
409+
assert_receive event(_, "stopped", %{
410+
"allThreadsStopped" => false,
411+
"reason" => "breakpoint",
412+
"threadId" => thread_id
413+
}),
414+
5_000
415+
416+
Server.receive_packet(server, stacktrace_req(7, thread_id))
417+
418+
assert_receive response(_, 7, "stackTrace", %{
419+
"totalFrames" => 1,
420+
"stackFrames" => [
421+
%{
422+
"column" => 0,
423+
"id" => frame_id,
424+
"line" => 4,
425+
"name" => "Abc.debug_me/0",
426+
"source" => %{"path" => ^abs_path}
427+
}
428+
]
429+
})
430+
when is_integer(frame_id)
431+
432+
Server.receive_packet(server, scopes_req(8, frame_id))
433+
434+
assert_receive response(_, 8, "scopes", %{
435+
"scopes" => [
436+
%{
437+
"expensive" => false,
438+
"indexedVariables" => 0,
439+
"name" => "variables",
440+
"namedVariables" => 1,
441+
"variablesReference" => vars_id
442+
},
443+
%{
444+
"expensive" => false,
445+
"indexedVariables" => 0,
446+
"name" => "versioned variables",
447+
"namedVariables" => 1,
448+
"variablesReference" => _vars_id
449+
},
450+
%{
451+
"expensive" => false,
452+
"indexedVariables" => 0,
453+
"name" => "process info",
454+
"namedVariables" => _,
455+
"variablesReference" => _
456+
}
457+
]
458+
})
459+
460+
Server.receive_packet(server, vars_req(9, vars_id))
461+
462+
assert_receive response(_, 9, "variables", %{
463+
"variables" => [
464+
%{
465+
"name" => "a",
466+
"type" => "list",
467+
"value" => "[1, 2, 3]",
468+
"variablesReference" => _
469+
}
470+
]
471+
}),
472+
1000
473+
474+
Server.receive_packet(server, continue_req(15, thread_id))
475+
assert_receive response(_, 15, "continue", %{"allThreadsContinued" => true})
476+
end)
477+
end
478+
358479
@tag :fixture
359480
test "launch with no debug", %{server: server} do
360481
in_fixture(__DIR__, "mix_project", fn ->
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
defmodule Abc do
2+
def debug_me() do
3+
a = [1, 2, 3]
4+
b = Enum.map(a, &(&1 + 1))
5+
b
6+
end
7+
end
8+
9+
a = [1, 2, 3]
10+
b = Enum.map(a, &(&1 + 1))
11+
IO.puts("done #{inspect(b)}, #{Abc.debug_me()}")
12+
13+
Task.start(fn ->
14+
Process.sleep(1000)
15+
IO.puts("done from task #{inspect(b)}, #{Abc.debug_me()}")
16+
end)

0 commit comments

Comments
 (0)