Skip to content

Commit 20b4e64

Browse files
committed
Print header on first dbg instruction, closes #14279
1 parent a7c008f commit 20b4e64

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

lib/elixir/lib/macro.ex

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,20 +2591,20 @@ defmodule Macro do
25912591
:ok
25922592
end
25932593

2594-
header = dbg_format_header(env)
2594+
prelude = quote do: options = unquote(Macro.escape(options))
25952595

2596-
prelude =
2597-
quote do
2598-
options = unquote(__MODULE__).__dbg_header__(unquote(header), unquote(options))
2599-
end
2596+
dbg_ast_to_debuggable(code, env)
2597+
|> Enum.reduce({prelude, dbg_format_header(env)}, fn entry, {acc, header} ->
2598+
acc =
2599+
quote do
2600+
unquote(acc)
2601+
to_debug = unquote(entry)
2602+
unquote(__MODULE__).__dbg__(to_debug, unquote(header), options)
2603+
end
26002604

2601-
Enum.reduce(dbg_ast_to_debuggable(code, env), prelude, fn entry, acc ->
2602-
quote do
2603-
unquote(acc)
2604-
to_debug = unquote(entry)
2605-
unquote(__MODULE__).__dbg__(to_debug, options)
2606-
end
2605+
{acc, nil}
26072606
end)
2607+
|> elem(0)
26082608
end
26092609

26102610
# Pipelines.
@@ -2841,24 +2841,18 @@ defmodule Macro do
28412841
# Made public to be called from Macro.dbg/3, so that we generate as little code
28422842
# as possible and call out into a function as soon as we can.
28432843
@doc false
2844-
def __dbg_header__(header_string, options) do
2844+
def __dbg__(to_debug, header, options) do
28452845
{print_location?, options} = Keyword.pop(options, :print_location, true)
2846+
ansi_enabled? = options[:syntax_colors] != []
28462847

2847-
if print_location? do
2848-
ansi_enabled? = options[:syntax_colors] != []
2849-
formatted = [:cyan, :italic, header_string, :reset, "\n"]
2848+
if print_location? and is_binary(header) do
2849+
formatted = [:cyan, :italic, header, :reset, "\n"]
28502850
:ok = IO.write(IO.ANSI.format(formatted, ansi_enabled?))
28512851
end
28522852

2853-
options
2854-
end
2855-
2856-
@doc false
2857-
def __dbg__(to_debug, options) do
28582853
syntax_colors = if IO.ANSI.enabled?(), do: IO.ANSI.syntax_colors(), else: []
28592854
options = Keyword.merge([width: 80, pretty: true, syntax_colors: syntax_colors], options)
28602855
{formatted, result} = dbg_format_ast_to_debug(to_debug, options)
2861-
ansi_enabled? = options[:syntax_colors] != []
28622856
:ok = IO.write(IO.ANSI.format([formatted, ?\n], ansi_enabled?))
28632857
result
28642858
end

0 commit comments

Comments
 (0)