Skip to content

Add mix help Mod, mix help :mod, mix help Mod.fun and mix help Mod.fun/arity #14246

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 8 commits into from
Feb 2, 2025

Conversation

renanroberto
Copy link
Contributor

Implementing issue #14244

Comment on lines 99 to 101
if Mix.Project.get() do
Mix.Tasks.Compile.run([])
end
Copy link
Member

Choose a reason for hiding this comment

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

I believe we can call loadpaths!()instead!

opts = Application.get_env(:mix, :colors)
opts = [width: width(), enabled: ansi_docs?(opts)] ++ opts
def run([task_or_module]) do
if Regex.match?(~r/(:|[A-Z]).*/, task_or_module) do
Copy link
Member

Choose a reason for hiding this comment

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

Instead of a regex, let's use pattern matching!

case task_or_module do
  <<first, _::binary>> when first in ?A..?Z or first == ?: ->

else
loadpaths!()
opts = Application.get_env(:mix, :colors)
opts = [width: width(), enabled: ansi_docs?(opts)] ++ opts
Copy link
Member

Choose a reason for hiding this comment

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

We need to apply this configuration to IEx as well, so maybe we need something like:

iex_colors = Application.get_env(:iex, :colors, [])

try do
  Application.put_env(:iex, :colors, Application.get_env(:mix, :colors))
  IEx.Introspection.h()
after
  Application.put_env(:iex, :colors, iex_colors)
end

replace regex for pattern match
apply colors configuration
use loadpaths! instead of compiling the project
@renanroberto
Copy link
Contributor Author

renanroberto commented Feb 1, 2025

Had some progress, but there still a test failing

test "errors when given {file, line} is not available" do
  assert capture_iex("open({~s[foo], 3})") =~
           "Could not open \"foo\", file is not available"
end
1) test open errors when given {file, line} is not available (IEx.HelpersTest)
   lib/iex/test/iex/helpers_test.exs:291
   Assertion with =~ failed
   code:  assert capture_iex("open({~s[foo], 3})") =~ "Could not open \"foo\", file is not available"
   left:  "Invalid arguments for open helper: {{:sigil_s, [delimiter: \"[\", line: 1], [{:<<>>, [line: 1], [\"foo\"]}, []]}, 3}"
   right: "Could not open \"foo\", file is not available"
   stacktrace:
     lib/iex/test/iex/helpers_test.exs:292: (test)

I plan to try to fix it tomorrow!


{fun, []} ->
{:{}, [], [find_decompose_fun_arity(fun, arity, context), fun, arity]}
{find_decompose_fun_arity(fun, arity, context), fun, arity}

_ ->
term
Copy link
Member

Choose a reason for hiding this comment

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

The error you are getting is because of this line here. We were previously returning the term as is, without escaping, and now we are escaping it always on IEx.Helpers. We also do it in the decompose clause below. My suggestion is to make it return :error instead.

Then, inside IEx.Helpers, you can write this helper:

defp decompose(term, context) do
  case IEx.Introspection.decompose(term, context) do
    :error -> term
    m_mf_mfa -> Macro.escape(m_mf_mfa)
  end
end

And then, in mix help, you raise if decompose returns :error.

Copy link
Contributor Author

@renanroberto renanroberto Feb 2, 2025

Choose a reason for hiding this comment

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

Great idea! I don't really know what to use on the raise message. Came up with Invalid expression: #{module} for now. Feel free to suggest something else!

And write a helper function on iex to Macro.espace
@josevalim josevalim merged commit b205181 into elixir-lang:main Feb 2, 2025
9 checks passed
@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