Bug: If the name of a class in a plugin file is changed, the plugin is not reloaded by Sublime until restarted

Keith Holman 8 years ago updated 8 years ago 0
I encountered this problem while writing my first plugin. I was using the Sublime API incorrectly, then renamed my plugin class, then fixed the error. I was then terribly confused because the Python console continued to complain about the old plugin and its error. The problem went away when I restarted Sublime. (The renamed plugin was loaded, and the non-existent ExampleCommand was no longer loaded.)

Repro follows:
  1. Launch Sublime Text 2
  2. Open the Python console (Ctrl+`)
  3. Click "Tools > New Plugin..."
  4. Save the new plugin as "Packages/User/example.py"
  5. Change the plugin to subclass "sublime_plugin.EventListener"
  6. Rename the "run" method to "on_pre_save"
  7. (The plugin now contains an API usage error, because it references "self.view", which does not exist in EventListener.)
  8. Save and observe that the error is reported in the Python console: "AttributeError: 'ExampleCommand' object has no attribute 'view'"
  9. Change the name of your plugin class to "MyNewPlugin"
  10. Remove the "self.view" reference in the plugin class and replace it with a line "print 'I am trying to fix my plugin!'"
  11. Save and observe that the Python console still complains about the error in ExampleCommand, which no longer exists. The new plugin, MyNewPlugin, won't run at all
  12. Make sure example.py (containing the MyNewPlugin plugin) is saved
  13. Close and restart Sublime Text 2
  14. The Python console will no longer report ExampleCommand issues, since it does not exist. Any MyNewPlugin behavior or errors now will show up.
Please let me know if you need any more information.