fchabouis

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

fchabouis

Thanks, I have all the information I need :heart:
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

hauleth

It is in the metadata of module itself. Just check out module.module_info().

fchabouis

fchabouis

@ambareesha7 No blog post, but I made a PR on Phoenix that just got merged!

hauleth

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

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.

fchabouis

fchabouis

In my case, I don’t think there is any overwriting, so that would be good enough!
I found how to get the module and function name with Phoenix.Router.route_info.
Code.fetch_docs/1 seems to be giving the line number in the file (thanks @hauleth ), I am just missing the name of the file :slight_smile:

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement