While working in Visual Studio a while back, I noticed a cool little feature that allows you to import method stubs for an interface you are implementing. Since I’m madly in love with Sublime Text, I decided to try and write a plugin that does the same thing.

This was my first stab at a Sublime Text plugin (and my first real look into Python actually), but I think it went pretty well. I don’t spend an ungodly amount of time implementing interfaces, but it was fun putting this together and I think it’s pretty cool. Technically the plugin doesn’t care if the target is an interface. It will work on any class, but it’s meant for interfaces and even abstract classes (if you want to override a method).

Check out the GitHub gist if you want to give the plugin a try. To set it up, save the python files from the gist to your Packages folder. I have mine at C:\Users\USERNAME\AppData\Roaming\Sublime Text 3\Packages\Implementer. Then create a key binding to trigger the plugin. My key binding is below.

Now to trigger the plugin, click on the name of the interface you want to implement and press your key binding (mine is f1). The plugin will give you a list of methods to choose from, or you can implement all of the methods.

I am just using a regular expression to parse the target class. It works pretty well, and it pulls in any parameters and type declarations too. I even tested a few PHP 7 features. Here’s a regex101 test with some examples.

sublime text 3 implement interface plugin