Skip to content

Commit a0e60f1

Browse files
authored
Add support for hover and clipboard eval in debugger (#680)
* add support for hover and clipboard eval in debugger * use empty string
1 parent ea250e2 commit a0e60f1

File tree

1 file changed

+33
-12
lines changed
  • apps/elixir_ls_debugger/lib/debugger

1 file changed

+33
-12
lines changed

apps/elixir_ls_debugger/lib/debugger/server.ex

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -550,20 +550,39 @@ defmodule ElixirLS.Debugger.Server do
550550
timeout = Map.get(state.config, "debugExpressionTimeoutMs", 10_000)
551551
bindings = all_variables(state.paused_processes, args["frameId"])
552552

553-
value = evaluate_code_expression(expr, bindings, timeout)
553+
result = evaluate_code_expression(expr, bindings, timeout)
554554

555-
child_type = Variables.child_type(value)
556-
{state, var_id} = get_variable_reference(child_type, state, :evaluator, value)
555+
case result do
556+
{:ok, value} ->
557+
child_type = Variables.child_type(value)
558+
{state, var_id} = get_variable_reference(child_type, state, :evaluator, value)
559+
560+
json =
561+
%{
562+
"result" => inspect(value),
563+
"variablesReference" => var_id
564+
}
565+
|> maybe_append_children_number(state.client_info, child_type, value)
566+
|> maybe_append_variable_type(state.client_info, value)
557567

558-
json =
559-
%{
560-
"result" => inspect(value),
561-
"variablesReference" => var_id
562-
}
563-
|> maybe_append_children_number(state.client_info, child_type, value)
564-
|> maybe_append_variable_type(state.client_info, value)
568+
{json, state}
565569

566-
{json, state}
570+
other ->
571+
result_string =
572+
if args["context"] == "hover" do
573+
# avoid displaying hover info when evaluation crashed
574+
""
575+
else
576+
inspect(other)
577+
end
578+
579+
json = %{
580+
"result" => result_string,
581+
"variablesReference" => 0
582+
}
583+
584+
{json, state}
585+
end
567586
end
568587

569588
defp handle_request(continue_req(_, thread_id) = args, state = %__MODULE__{}) do
@@ -739,7 +758,7 @@ defmodule ElixirLS.Debugger.Server do
739758
result = Task.yield(task, timeout) || Task.shutdown(task)
740759

741760
case result do
742-
{:ok, data} -> data
761+
{:ok, data} -> {:ok, data}
743762
nil -> :elixir_ls_expression_timeout
744763
_otherwise -> result
745764
end
@@ -952,6 +971,8 @@ defmodule ElixirLS.Debugger.Server do
952971
"supportsExceptionInfoRequest" => false,
953972
"supportsTerminateThreadsRequest" => true,
954973
"supportsSingleThreadExecutionRequests" => true,
974+
"supportsEvaluateForHovers" => true,
975+
"supportsClipboardContext" => true,
955976
"supportTerminateDebuggee" => false
956977
}
957978
end

0 commit comments

Comments
 (0)