Get all commands registered by a package

I’m looking for a way to programmatically get all commands registered by a package. Neither the CommandRegistry API nor the PackageManager API expose any documented methods for this. While atom.commands.registeredCommands list all registered commands, that’s not a reliable way to associate a command to a package since the command prefix should, but doesn’t have to match the package name. Using atom.packages.getLoadedPackage(packageName) lists all activation commands of a package (which could also be retrieved from the package manifest), but that doesn’t include commands that are not bound to the activation event.

Any ideas?

3 Likes

Hey idleberg,

FYI, I have looked for this also and came up empty. Getting the keymaps registered by a package is possible because they have a ‘source’ field set to the file path that they were loaded from. If you dynamically add a keymap it expects you to provide a source field which probably should be your package name but is not enforced.

Since commands are only registered at dynamically via CommandRegistry::add and that api call does not require or even support providing anything that identifies the package that is making the call, it seems like the information just does not exist.

It seems like that api should have a source input like keymaps but does not.

The activation commands are listed only because its part of the package.json data. As you mentioned, that’s almost never a complete list.

I wonder if the CommandRegistry::add function could be enhanced to glean the package name from the call stack?

–BobG

I‘ve created a feature request on GitHub, please like/subscribe if you‘re interested