【问题标题】:How to list callers of a function in Elixir?如何在 Elixir 中列出函数的调用者?
【发布时间】:2021-12-09 16:23:25
【问题描述】:

我正在重构一个函数,我想知道调用它的每个文件。使用别名和导入,简单的 grep 会列出不同模块中具有相同名称的其他函数,或者会错过一些调用。

我尝试使用mix xref,但它不适用于函数,只能用于模块(我使用的是 Elixir 1.12.1)。

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

是否有工具或外部参照命令可以列出 Elixir 中函数的调用者?

【问题讨论】:

    标签: debugging elixir


    【解决方案1】:

    有一个已弃用的 Mix.Tasks.Xref.calls/1 函数,但它已被弃用是有原因的,Compilation tracers 更强大。

    您可以为{:remote_function, _, YourModule, :your_fun, your_arity} 设置跟踪器,然后从那里简单地设置IO.puts/2

    【讨论】:

      猜你喜欢
      • 2016-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多