Listing all names available in a module, part 2

Follow-up to Listing all names available in a module.

I need a way to introspect all names available in a module, including names implicitly brought in with using. The names function is helpful, but does not go all the way because even with imported=true it only includes names explicitly brought into a module.

Inside a module MyModule which states
using FunctionalCollections
the invocation of names(MyModule, imported=true) does not include names from FunctionalCollections. On the other hand if MyModule states
import FunctionalCollections: @Persistent, append
the names command does include the explicitly imported symbols. (Strangely, using FunctionalCollections: @Persistent, append does not have the same effect as the import call above.)

In short, is there a more powerful version of names I can use to enumerate all names available inside a module?

You can do it iteratively:

nms = names(MyModule; imported=true)
for mod in Base.loaded_modules_array()
    if isdefined(MyModule, nameof(mod))
        append!(nms, names(mod))
    end
end
6 Likes

Excellent workaround. Thank you.