Developing the plugin
Now that we have a plugin with a basic command that shows up in the command palette, we can start developing our plugin; we'll start with hiding the command when it's unusable. We'll do it by overriding the is_visible
function and checking that the current file extension is .rb
and the first line contains a ActiveRecord::Base
inheritance. Let's import the python os
lib by adding import os
below the import sublime
line. Add the following to our command:
def is_visible(self): view = self.window.active_view() file_name, file_extension = os.path.splitext(view.file_name()) return file_extension == ".rb" and "ActiveRecord::Base" in view.substr(view.line(0))
When the command palette is being opened, it will run all the is_visible
functions of all the exposed commands to check whether or not they should be shown. We are checking whether or not the current view (file) extension is set as .rb
and the first line of the file contains ActiveRecord::Base
and only if both conditions...