I was going through filling up another two pages with exhaustive lists of from foo import `[]`, const1, const2, const3, const4, const5, ... and it occurred to me, if I import "`[]`" from a bunch of different modules, even if I use the from X import Y syntax, I still can't tell which "`[]`" is being invoked when I have foo[bar] in my code!
Is there a way to list the symbols in a module, and find what other module each of them was imported from? That seems like it could be really useful to understanding someone else's code, where without any way to track the imports, you're fighting through a nightmare of spaghetti and magic trying to figure out what their code does at all. What might be even better is a way to list those "modules of origin" and any modules the symbol was then re-exported from. So if you go import kitchen_sink then people who are cursed to deal with your code are still not entirely without recourse.
Does this already exist? I don't know if it would be a macro, or a command line option to the compiler, or what. Or horribly complicated and not worth implementing.
I think lineInfo is what I'm looking for, and it looks like it exists! Combined with getType, since otherwise it's just the file that the findsym statement is in.
from macros import lineInfo,getType
macro findsym(x: typed): untyped =
debugEcho(lineInfo(x.getType))
findsym:
lineInfo
=> /usr/lib/nim/core/macros.nim(522, 14)