fchabouis
How to get function definition file and line?
I would like to know if there is a way, in a mix project, to get information about where a function is defined?
I would like, given a module name and function name, to know that this function is defined line 8 of foo.ex file. I guess it is possible to find information like this, as we get lines number when running tests or for compiler warnings.
Thanks!
Marked As Solved
fchabouis
Thanks, I have all the information I need ![]()
Phoenix.Router.route_info to know which module + function is called
module.module_info() for the source file path
Code.fetch_docs/1 for the line number
Also Liked
hauleth
It is in the metadata of module itself. Just check out module.module_info().
fchabouis
@ambareesha7 No blog post, but I made a PR on Phoenix that just got merged!
hauleth
You can try to extract that information from the Code.fetch_docs/1. It will not always be 100% precise (as if there is documentation, then it will point to the line for documentation), but works well enough, especially in presence of multiple heads.
LostKobrakai
Phoenix.Router — Phoenix v1.6.6 can give you the plug / plug_opts (action). But MyController.action/2 can be overwritten, so you cannot be sure that MyController, :index actually calls MyController.index/2.







