Skip to content
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

Fix IEx doc printing for headings with newline characters #13018

Merged
merged 2 commits into from
Oct 20, 2023

Conversation

dinocosta
Copy link
Contributor

Update IEx.introspection.print_doc/5 to trasverse the list of headings and split each heading into multiple headings, in case the heading has any newline characters (\n). This fixes an issue where using the h macro with some functions ended up with a broken output for the function signature, as the padding done by IO.ANSI.Docs.print_headings/2 does not take into consideration the fact the the headings can contain newline characters, and thus end up in multiple lines.

Here's a before and after comparison of running h dbg in iex:

Before

image

After

image

Update `IEx.introspection.print_doc/5` to trasverse the list of headings
and split each heading into multiple headings, in case the heading has
any newline characters (`\n`). This fixes an issue where using the `h`
macro with some functions ended up with a broken output for the function
signature, as the padding done by `IO.ANSI.Docs.print_headings/2` does
not take into consideration the fact the the headings can contain
newline characters, and thus end up in multiple lines.
- Move the fix for headings with newline characters from
  `IEx.Introspection.print_doc/5` to `IO.ANSI.Docs.print_headings/1,2`.
- Apply suggestion to use `Enum.flat_map/2` over `Enum.map/2` followed
  by `Enum.flatten/1`.
- Create new test case to make sure `IO.ANSI.Docs.print_headings`
  correctly formats headings with newline characters.
@josevalim josevalim merged commit d332f26 into elixir-lang:main Oct 20, 2023
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

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.

2 participants