sublimetexttext-editorsublimereplpackage-control

How to log commands that are run through command palette in Sublime Text 3


I know that commands can be logged by going to the console View -> Show Console and typing

sublime.log_commands(True)

However, the commands that are run through the command palette are not logged, it just shows:

command: show_overlay {"overlay": "command_palette"}

Is there a way to log the commands run through the palette?


Solution

  • There's not currently a way to log the commands that are being executed from the command palette, no. If I recall correctly, this was possible in older builds of Sublime, but around the time that the command palette gained the ability to accept input for commands like View Package File, it stopped working. That might be an offshoot of the mechanism that's used to trigger input handling in the command palette, but that's just a guess.

    Normally a plugin could be used to track something like this because EventListener classes have events to tell you before and after commands execute. However, there's an open issue on the tracker regarding the command palette on triggering on_post_window_command which is likely caused by the same thing as the commands not showing up in the log.

    Currently the only way to know what command and arguments are being invoked from the command palette is to introspect the sublime-commands file that's providing them.

    Unlike menus, commands in the command palette are not allowed to have dynamic captions, so it's a relatively simple matter to find the command entry that has a "caption" for the text you know you're picking.

    The tricky part can be in determining where the command is coming from. In the console, sublime.find_resources('*.sublime-commands') will show you a list of every known command file, and you can open them via View Package File in the command palette.

    Generally, anything that ships with Sublime is in Default/Default.sublime-commands, and anything that's added by a package is prefixed by the name of the package that added it, which can aid in determining what file to check.

    Note that there are some commands in the command palette that are added by Sublime and don't come from a command file; commands that insert snippets and commands that change the syntax. Those are determined on the fly since the list of syntaxes and snippets is subject to change.