Skip to content

Commit

Permalink
Allow configuring debugExpressionTimeoutMs (#613)
Browse files Browse the repository at this point in the history
* Allow configuring debugExpressionTimeoutMs

Rather than a hard-coded timeout of 1_000 ms for watch expressions, add
`debugExpressionTimeoutMs` to the launch.json configuration options. In
the next version of vscode-elixir-ls `debugExpressionTimeoutMs` will be
supported in the launch.json autocomplete, but if you are running a
version of ElixirLS that supports it before then you can add the key
manually.

Example mix test launch.json entry that uses this to set a timeout of 30
seconds:
```
{
    "type": "mix_task",
    "name": "mix test",
    "request": "launch",
    "debugExpressionTimeoutMs": 30000,
    "task": "test",
    "taskArgs": [
        "--trace"
    ],
    "startApps": true,
    "projectDir": "${workspaceRoot}",
    "requireFiles": [
        "test/**/test_helper.exs",
        "test/**/*_test.exs"
    ]
}
```

Fixes #525

* Fix test
  • Loading branch information
axelson authored Oct 21, 2021
1 parent db38656 commit 37dd730
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/elixir_ls_debugger/lib/debugger/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ defmodule ElixirLS.Debugger.Server do
request(_cmd, "evaluate", %{"expression" => expr} = _args),
state = %__MODULE__{}
) do
timeout = 1_000
timeout = Map.get(state.config, "debugExpressionTimeoutMs", 10_000)
bindings = all_variables(state.paused_processes)

result = evaluate_code_expression(expr, bindings, timeout)
Expand Down
26 changes: 20 additions & 6 deletions apps/elixir_ls_debugger/test/debugger_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ defmodule ElixirLS.Debugger.ServerTest do
end

describe "Watch section" do
defp gen_packet(expr) do
defp gen_watch_expression_packet(expr) do
%{
"arguments" => %{
"context" => "watch",
Expand All @@ -527,7 +527,7 @@ defmodule ElixirLS.Debugger.ServerTest do

Server.receive_packet(
server,
gen_packet("1 + 2 + 3 + 4")
gen_watch_expression_packet("1 + 2 + 3 + 4")
)

assert_receive(%{"body" => %{"result" => "10"}}, 1000)
Expand All @@ -541,7 +541,7 @@ defmodule ElixirLS.Debugger.ServerTest do

Server.receive_packet(
server,
gen_packet("1 = 2")
gen_watch_expression_packet("1 = 2")
)

assert_receive(%{"body" => %{"result" => result}}, 1000)
Expand All @@ -556,7 +556,7 @@ defmodule ElixirLS.Debugger.ServerTest do

Server.receive_packet(
server,
gen_packet("Process.exit(self(), :normal)")
gen_watch_expression_packet("Process.exit(self(), :normal)")
)

assert_receive(%{"body" => %{"result" => result}}, 1000)
Expand All @@ -571,7 +571,7 @@ defmodule ElixirLS.Debugger.ServerTest do

Server.receive_packet(
server,
gen_packet("throw(:goodmorning_bug)")
gen_watch_expression_packet("throw(:goodmorning_bug)")
)

assert_receive(%{"body" => %{"result" => result}}, 1000)
Expand All @@ -583,10 +583,24 @@ defmodule ElixirLS.Debugger.ServerTest do

test "Evaluate expression which has long execution", %{server: server} do
Server.receive_packet(server, initialize_req(1, %{}))
assert_receive(response(_, 1, "initialize", %{"supportsConfigurationDoneRequest" => true}))

Server.receive_packet(
server,
launch_req(2, %{
"request" => "launch",
"type" => "mix_task",
"task" => "test",
"projectDir" => File.cwd!(),
"debugExpressionTimeoutMs" => 500
})
)

assert_receive(response(_, 2, "launch", %{}), 5000)

Server.receive_packet(
server,
gen_packet(":timer.sleep(10_000)")
gen_watch_expression_packet(":timer.sleep(10_000)")
)

assert_receive(%{"body" => %{"result" => result}}, 1100)
Expand Down

0 comments on commit 37dd730

Please sign in to comment.