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
Add mix xref --callers M.f/a
#4683
Add mix xref --callers M.f/a
#4683
Conversation
fb1be84
to
56c4ba5
Compare
Thank you @antipax! We should get feedback from @tonini and @msaraiva but I would stick with the following for formatting: lib/a.ex:2: A.a/0
lib/a.ex:3: A.a/0 The idea is that this is a common format for Elixir developers, since we see it frequently in stacktraces and there is a chance editors are already parsing those. :) |
I have no problem changing it, but what about paths like "lib/my:crazy:path/a.ex"? |
@@ -144,6 +144,7 @@ do_expand_import(Meta, {Name, Arity} = Tuple, Args, Module, E, Result) -> | |||
check_deprecation(Meta, Receiver, Name, Arity, E), | |||
elixir_lexical:record_import({Receiver, Name, Arity}, ?m(E, lexical_tracker)), | |||
elixir_locals:record_import(Tuple, Receiver, Module, ?m(E, function)), | |||
elixir_lexical:record_remote(Receiver, Name, Arity, nil, ?line(Meta), ?m(E, lexical_tracker)), |
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.
Preferably we would add record_import/6
and call the lexical tracker just once and it would write to both places.
It is still easy to match on ":\d+: " if you need a reference point. :) On Wednesday, May 25, 2016, Eric Entin notifications@github.com wrote:
José Valimwww.plataformatec.com.br |
## Print callers | ||
|
||
defp print_calls(file, calls) do | ||
IO.write(["file: ", file, ?\n]) |
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 can use IO.puts/1
here, and on later line as well.
defp source_calls_for_filter(source, filter) do | ||
runtime_dispatches = source(source, :runtime_dispatches) | ||
compile_dispatches = source(source, :compile_dispatches) | ||
dispatches = merge_dispatches(runtime_dispatches, compile_dispatches) |
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.
This could be improved by merging dispatches after filtering them, I suppose. Let me know if I should make the change.
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'm just gonna go for it actually.
Tests are passing but do not merge, there is an issue with the last commit. |
@@ -134,13 +138,16 @@ defmodule Kernel.LexicalTracker do | |||
end | |||
|
|||
def handle_cast({:import_dispatch, {module, function, arity}}, state) 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.
Do we still need this format? Can we write all of them in the format below? :)
@antipax thank you! I have added my last batch of comments. ❤️ |
Ok, unless anyone has any further comments I think this is ready to be merged. |
{{func, arity}, lines} <- fals, | ||
line <- lines, | ||
do: {line, module, func, arity}) | ||
|> Enum.sort() |
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 assume there is no need for sorting.
a0abc6e
to
2b0b8b8
Compare
❤️ 💚 💙 💛 💜 |
Related: #4656.
mix xref --callers
accepts aModule
,Module.function
, orModule.function/arity
.Output looks like:
I chose this format because:
:
and"
and,
) and this should hopefully simplify parsing for libraries that will rely on the output of this task without having to define any kind of escapingThe task also returns data like:
from
run
, so if you use it from within Elixir itself you don't have to parse anything.Do we need any additional switches, like maybe
--silent
(for use from Elixir apps that will simply use the return value ofrun
)?I also added some missing
record_remote
s to get all of our compile dispatches in, and also fixed a bug where xref was not checking captured remotes./cc @josevalim