简体   繁体   English

如何记录通过 Sublime Text 3 中的命令面板运行的命令

[英]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我知道可以通过转到控制台View -> Show Console并键入来记录命令

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?有没有办法记录通过调色板运行的命令?

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.如果我没记错的话,这在较旧的 Sublime 版本中是可能的,但是大约在命令面板获得接受诸如View Package File类的命令输入的能力时,它停止工作。 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.通常可以使用插件来跟踪这样的事情,因为EventListener类具有在命令执行之前和之后告诉您的事件。 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.但是,跟踪器上存在一个关于触发 on_post_window_command 的命令面板的未解决问题,这可能与日志中未显示的命令相同。

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.目前,了解从命令面板调用哪些命令和参数的唯一方法是内省提供它们的sublime-commands文件。

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.与菜单不同,命令面板中的命令不允许具有动态标题,因此找到具有您所选择的文本的"caption"的命令条目是一件相对简单的事情。

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.在控制台中, sublime.find_resources('*.sublime-commands')将显示每个已知命令文件的列表,您可以通过命令面板中的View Package File打开它们。

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.通常,Sublime 附带的任何内容都在Default/Default.sublime-commands ,并且包添加的任何内容都以添加它的包的名称作为前缀,这有助于确定要检查的文件。

Note that there are some commands in the command palette that are added by Sublime and don't come from a command file;请注意,命令面板中有一些命令是由 Sublime 添加的,而不是来自命令文件; 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.这些是即时确定的,因为语法和片段列表可能会发生变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM