Skip to content

Commit bb8689f

Browse files
authored
Use IEx.Pry.annotate_quoted/3 in IEx.Pry.dbg/3 (elixir-lang#13457)
1 parent 12f62e4 commit bb8689f

File tree

1 file changed

+9
-29
lines changed

1 file changed

+9
-29
lines changed

lib/iex/lib/iex/pry.ex

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ defmodule IEx.Pry do
111111
@doc """
112112
Annotate quoted expression with line-by-line `IEx.Pry` debugging steps.
113113
114-
It expected the `quoted` expression to annotate, a `condition` that controls
114+
It expects the `quoted` expression to annotate, a boolean `condition` that controls
115115
if pry should run or not (usually is simply the boolean `true`), and the
116116
caller macro environment.
117117
"""
@@ -665,9 +665,10 @@ defmodule IEx.Pry do
665665
def dbg({:|>, _meta, _args} = ast, options, %Macro.Env{} = env) when is_list(options) do
666666
[first_ast_chunk | asts_chunks] = ast |> Macro.unpipe() |> chunk_pipeline_asts_by_line(env)
667667

668-
initial_acc = [
668+
{first_line, _max_line} = line_range(ast, env.line)
669+
670+
prelude =
669671
quote do
670-
env = __ENV__
671672
options = unquote(options)
672673

673674
options =
@@ -677,9 +678,6 @@ defmodule IEx.Pry do
677678
options
678679
end
679680

680-
env = unquote(env_with_line_from_asts(first_ast_chunk))
681-
682-
next? = IEx.Pry.__next__(true, binding(), env)
683681
value = unquote(pipe_chunk_of_asts(first_ast_chunk))
684682

685683
IEx.Pry.__dbg_pipe_step__(
@@ -689,16 +687,12 @@ defmodule IEx.Pry do
689687
options
690688
)
691689
end
692-
]
693690

694-
for asts_chunk <- asts_chunks, reduce: initial_acc do
695-
ast_acc ->
691+
main_block =
692+
for asts_chunk <- asts_chunks do
696693
piped_asts = pipe_chunk_of_asts([{quote(do: value), _index = 0}] ++ asts_chunk)
697694

698695
quote do
699-
unquote(ast_acc)
700-
env = unquote(env_with_line_from_asts(asts_chunk))
701-
next? = IEx.Pry.__next__(next?, binding(), env)
702696
value = unquote(piped_asts)
703697

704698
IEx.Pry.__dbg_pipe_step__(
@@ -708,7 +702,9 @@ defmodule IEx.Pry do
708702
options
709703
)
710704
end
711-
end
705+
end
706+
707+
annotate_quoted({:__block__, [], [prelude | main_block]}, true, %{env | line: first_line})
712708
end
713709

714710
def dbg(ast, options, %Macro.Env{} = env) when is_list(options) do
@@ -753,20 +749,4 @@ defmodule IEx.Pry do
753749
defp asts_chunk_to_strings(asts) do
754750
Enum.map(asts, fn {ast, _pipe_index} -> Macro.to_string(ast) end)
755751
end
756-
757-
defp env_with_line_from_asts(asts) do
758-
line =
759-
Enum.find_value(asts, fn
760-
{{_fun_or_var, meta, _args}, _pipe_index} -> meta[:line]
761-
{_ast, _pipe_index} -> nil
762-
end)
763-
764-
if line do
765-
quote do
766-
%{env | line: unquote(line)}
767-
end
768-
else
769-
quote do: env
770-
end
771-
end
772752
end

0 commit comments

Comments
 (0)