@@ -111,7 +111,7 @@ defmodule IEx.Pry do
111
111
@ doc """
112
112
Annotate quoted expression with line-by-line `IEx.Pry` debugging steps.
113
113
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
115
115
if pry should run or not (usually is simply the boolean `true`), and the
116
116
caller macro environment.
117
117
"""
@@ -665,9 +665,10 @@ defmodule IEx.Pry do
665
665
def dbg ( { :|> , _meta , _args } = ast , options , % Macro.Env { } = env ) when is_list ( options ) do
666
666
[ first_ast_chunk | asts_chunks ] = ast |> Macro . unpipe ( ) |> chunk_pipeline_asts_by_line ( env )
667
667
668
- initial_acc = [
668
+ { first_line , _max_line } = line_range ( ast , env . line )
669
+
670
+ prelude =
669
671
quote do
670
- env = __ENV__
671
672
options = unquote ( options )
672
673
673
674
options =
@@ -677,9 +678,6 @@ defmodule IEx.Pry do
677
678
options
678
679
end
679
680
680
- env = unquote ( env_with_line_from_asts ( first_ast_chunk ) )
681
-
682
- next? = IEx.Pry . __next__ ( true , binding ( ) , env )
683
681
value = unquote ( pipe_chunk_of_asts ( first_ast_chunk ) )
684
682
685
683
IEx.Pry . __dbg_pipe_step__ (
@@ -689,16 +687,12 @@ defmodule IEx.Pry do
689
687
options
690
688
)
691
689
end
692
- ]
693
690
694
- for asts_chunk <- asts_chunks , reduce: initial_acc do
695
- ast_acc ->
691
+ main_block =
692
+ for asts_chunk <- asts_chunks do
696
693
piped_asts = pipe_chunk_of_asts ( [ { quote ( do: value ) , _index = 0 } ] ++ asts_chunk )
697
694
698
695
quote do
699
- unquote ( ast_acc )
700
- env = unquote ( env_with_line_from_asts ( asts_chunk ) )
701
- next? = IEx.Pry . __next__ ( next? , binding ( ) , env )
702
696
value = unquote ( piped_asts )
703
697
704
698
IEx.Pry . __dbg_pipe_step__ (
@@ -708,7 +702,9 @@ defmodule IEx.Pry do
708
702
options
709
703
)
710
704
end
711
- end
705
+ end
706
+
707
+ annotate_quoted ( { :__block__ , [ ] , [ prelude | main_block ] } , true , % { env | line: first_line } )
712
708
end
713
709
714
710
def dbg ( ast , options , % Macro.Env { } = env ) when is_list ( options ) do
@@ -753,20 +749,4 @@ defmodule IEx.Pry do
753
749
defp asts_chunk_to_strings ( asts ) do
754
750
Enum . map ( asts , fn { ast , _pipe_index } -> Macro . to_string ( ast ) end )
755
751
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
772
752
end
0 commit comments