Skip to content

First implementation of Kernel.dbg/2 #11974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jul 12, 2022
Merged

First implementation of Kernel.dbg/2 #11974

merged 25 commits into from
Jul 12, 2022

Conversation

whatyouhide
Copy link
Member

No description provided.

@whatyouhide whatyouhide requested a review from josevalim July 10, 2022 07:19
@josevalim
Copy link
Member

It is looking awesome, I have added some comments. I am wondering if we should call it dbg or dbg! but there is likely not much reason to have a !.

@whatyouhide
Copy link
Member Author

@josevalim this is ready for another round of review.

@whatyouhide whatyouhide changed the title Initial work on Kernel.dbg/2 First implementation of Kernel.dbg/2 Jul 11, 2022

quote do
unquote(values_ast)
{:pipe, unquote(escape(asts)), Enum.reverse(unquote(values_acc_var))}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am almost 100% you can convert the asts to string here, instead of escaping them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅


# Any other AST.
defp dbg_ast_to_debuggable(ast) do
quote do: {:value, unquote(escape(ast)), unquote(ast)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅

Copy link
Member

@josevalim josevalim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just very minor comments left. :)

whatyouhide and others added 11 commits July 11, 2022 15:54
Comment on lines +273 to +279
defmacrop dbg_format(ast, options \\ quote(do: [syntax_colors: []])) do
quote do
ExUnit.CaptureIO.with_io(fn ->
unquote(Macro.dbg(ast, options, __CALLER__))
end)
end
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opted to avoid the "no I/O" testing strategy for now in favor of simplicity. Testing with capturing I/O lets us keep the code in Macro simpler, with less functions involved. This should be fast enough for now. If we add a lot more tests, we can always go back to a purely-functional testing approach by reworking the new Macro functions slightly.


quote do
unquote(values_ast)
{:pipe, unquote(escape(asts)), Enum.reverse(unquote(values_acc_var))}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅


# Any other AST.
defp dbg_ast_to_debuggable(ast) do
quote do: {:value, unquote(escape(ast)), unquote(ast)}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅

@whatyouhide whatyouhide force-pushed the andrea/start-dbg-macro branch from 64ed871 to 6330524 Compare July 11, 2022 14:06
@whatyouhide whatyouhide marked this pull request as ready for review July 11, 2022 14:39
@whatyouhide whatyouhide requested a review from josevalim July 11, 2022 14:39
@whatyouhide
Copy link
Member Author

@josevalim ready for final review, I think.

Copy link
Member

@josevalim josevalim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful!!!

Copy link
Member

@fertapric fertapric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

@whatyouhide whatyouhide merged commit a8bf349 into main Jul 12, 2022
@whatyouhide whatyouhide deleted the andrea/start-dbg-macro branch July 12, 2022 07:32
@wojtekmach
Copy link
Member

This is amazing!

Two quick questions. For this file:

# foo.exs
dbg("foo")

"foo" |> String.upcase() |> dbg

I'm getting:

[foo.exs:1: (file)]
"foo" #=> "foo"

[foo.exs:3: (file)]
|> "foo" #=> "foo"
|> String.upcase() #=> "FOO"


  1. Notice two blank lines after a pipe. Should there be one blank line, like everywhere else?
  2. Notice the printed pipeline starts with |> "foo". Should it be just "foo"?

@jonatanklosko
Copy link
Member

@whatyouhide fantastic job!! 🐱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants