igniter/lib/debug.ex
Zach Daniel 067c4a6df0 improvement: various restructurings and improvements across the board
improvement: use `Spitfire` to ensure that aliases are considered when comparing modules
improvement: use `Spitfire` to *use* any existing aliases when inserting code
improvement: use `Zipper.topmost` to power new `Spitfire`-related features
2024-06-14 17:07:32 -04:00

35 lines
827 B
Elixir

defmodule Igniter.Debug do
@moduledoc "Tools for debugging zippers."
alias Sourceror.Zipper
@doc "Puts the formatted code at the node of the zipper to the console"
def puts_code_at_node(zipper) do
zipper
|> Zipper.subtree()
|> Zipper.root()
|> Sourceror.to_string()
|> then(&"==code==\n#{&1}\n==code==\n")
|> IO.puts()
zipper
end
@doc "Returns the formatted code at the node of the zipper to the console"
def code_at_node(zipper) do
zipper
|> Zipper.subtree()
|> Zipper.root()
|> Sourceror.to_string()
end
@doc "Puts the ast at the node of the zipper to the console"
def puts_ast_at_node(zipper) do
zipper
|> Zipper.subtree()
|> Zipper.root()
|> then(&"==ast==\n#{inspect(&1, pretty: true)}\n==ast==\n")
|> IO.puts()
zipper
end
end