-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
This is necessary to have access to the docs inside the project
lib/mix/lib/mix/tasks/help.ex
Outdated
if Mix.Project.get() do | ||
Mix.Tasks.Compile.run([]) | ||
end |
There was a problem hiding this comment.
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!
lib/mix/lib/mix/tasks/help.ex
Outdated
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 |
There was a problem hiding this comment.
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 == ?: ->
lib/mix/lib/mix/tasks/help.ex
Outdated
else | ||
loadpaths!() | ||
opts = Application.get_env(:mix, :colors) | ||
opts = [width: width(), enabled: ansi_docs?(opts)] ++ opts |
There was a problem hiding this comment.
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
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
I plan to try to fix it tomorrow! |
lib/iex/lib/iex/introspection.ex
Outdated
|
||
{fun, []} -> | ||
{:{}, [], [find_decompose_fun_arity(fun, arity, context), fun, arity]} | ||
{find_decompose_fun_arity(fun, arity, context), fun, arity} | ||
|
||
_ -> | ||
term |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
💚 💙 💜 💛 ❤️ |
Implementing issue #14244