Home > OS >  How to list callers of a function in Elixir?
How to list callers of a function in Elixir?

Time:12-11

I'm refactoring a function and I want to know every file that calls it. With aliases and imports, a simple grep would list other functions with the same name in different modules or would miss some calls.

I tried using mix xref but it doesn't work with functions, only modules (I'm using Elixir 1.12.1).

$ mix xref callers MySchema.changeset/2
** (Mix) xref callers MODULE expects a MODULE, got: MySchema.changeset/2

Is there a tool or a xref command to list callers of a function in Elixir?

CodePudding user response:

There is a deprecated Mix.Tasks.Xref.calls/1 function, but it has been deprecated for a reason, Compilation tracers are way more powerful.

You might set a tracer for {:remote_function, _, YourModule, :your_fun, your_arity} and simply IO.puts/2 from there.

  • Related