diff --git a/lib/livebook/runtime/evaluator.ex b/lib/livebook/runtime/evaluator.ex index 255c4574dfb..e176c647db4 100644 --- a/lib/livebook/runtime/evaluator.ex +++ b/lib/livebook/runtime/evaluator.ex @@ -649,9 +649,8 @@ defmodule Livebook.Runtime.Evaluator do quoted = Code.string_to_quoted!(code, file: env.file) try do - {value, binding, env} = - Code.eval_quoted_with_env(quoted, binding, env, prune_binding: true) - + opts = maybe_dbg_callback() ++ [prune_binding: true] + {value, binding, env} = Code.eval_quoted_with_env(quoted, binding, env, opts) {:ok, value, binding, env} catch kind, error -> @@ -706,6 +705,15 @@ defmodule Livebook.Runtime.Evaluator do {result, code_markers} end + defp maybe_dbg_callback() do + if Code.ensure_loaded?(Kino.Debug) do + original = Application.fetch_env!(:elixir, :dbg_callback) + [{:dbg_callback, {Kino.Debug, :dbg, [original]}}] + else + [] + end + end + defp extra_diagnostic?(%SyntaxError{}), do: true defp extra_diagnostic?(%TokenMissingError{}), do: true defp extra_diagnostic?(%MismatchedDelimiterError{}), do: true