Sublime Forum

What does window.run_command("gs_log" do?

#1

Trying to learn plugin dev for adding a feature in this plugin: github.com/divmain/GitSavvy
On core\commands\log.py:98 there’s

self.window.run_command("gs_log", {"filename": self.file_path})

This is supposed to run git log (or some variation of it) but I’m trying to understand what exactly does run_command do?
I’m looking at the API reference where it says it “Runs the named Command with the (optional) given arguments. Window.run_command is able to run both any sort of command, dispatching the command via input focus.”

So it’s obviously running the gs_log command but where exactly does gs_log come from? I’ve searched the code for gs_log but all mentions of it are only in using it, I couldn’t find the actual definition anywhere. Either the definition is not by the same name (gs_log), or that it’s actually a part of Sublime itself (I’m thinking unlikely because I couldn’t find anything).

Essentially I want to find out where exactly does this code go next? Where might gs_log be defined?

Any help appreciated…

0 Likes

#2

I’ll guide you through this.

  1. since gs_log most definitely does not exist in Sublime Text by default and the gs prefix heavily implies its roots from “GitSavvy”, it is very likely to be defined there.

  2. commands are created by exposing classes in a .py file that is under the package’s root directory (so Packages/Users for example), which subclass one of the sublime_plugin.*Command classes. “Exposed” means just being available as a global in a module.

  3. The only .py file that’s inside the top level of the GitSavvy package is git_savvy.py, which does not define any command directly. However, it has a few imports in it, which also end up in the global scope, and from .common.commands import * sounds pretty promising.

  4. So I browsed common/commands/__init__.py, which also containes several imports. But neither of the imported files had a GsLogCommand class defined.

  5. In git_savvy.py there was another promising import from .core.commands import *, which leads to core/commands/__init__.py.

  6. And in /core/commands/log.py you can finally find the GsLogCommand class: github.com/divmain/GitSavvy/blo … /log.py#L8

0 Likes