Sublime Forum

Plugin doesnt load until i save it

#1

Hey all first post

I have 2 new ST3 plugins i’ve developed that are both working great

… except one issue…

Both plugins won’t load and commands wont run unil i save the source file at least once. After that, everything is awesome, until i close ST3 again.

id like to release the plugins but obviously I cant do that until this is solved. It must be something simple… everything else is working fine, menus, context menus, the plugins themselves, metadata, for them etc etc.

Just wont autoload when ST3 starts.

Its weird because package control detects them and im able to remove them/creat binary package file. But the commands just wont run until i save the document…annoying.

Any ideas?

0 Likes

#2

Any ideas?

Yes, post the source

0 Likes

#3

uh, continue here

0 Likes

#4

Ok so some good news,

I have narrowed it down now and it had to do with settings initialization. This problem has been bugging me for weeks and I finally cracked it as my completed plugin was just sitting there ready to be released.This was odd because every other setting was being initialized and used throughout the code in exactly the same fashion, and there are quite a few variables and various checks…all working 100%, except this one setting.

For anyone else having this problem how i figured it out was to open and close ST3, then immediately before doing anything else open the console (ctrl-tilde) and run the plugin command to check for errors.

I could then see the plugin was loading correctly, however I was getting a compile error. (yeah i know duh right) but the thing is it was error free in my linter, and error free in ST3 after a save so i just missed it somehow…The fix was to reinitialize my master settings variable inside the class that was being called.

The error I was getting : TypeError: argument of type ‘NoneType’ is not iterable… yet the setting was defined in the settings file as so:

“file_types” : “php”, “htm”, “html”],

And even more strangely, after a save the list variable did become iterable. Say what???

Have a look:


# global settings variable
s = sublime.load_settings("PhpBeautify.sublime-settings")

...
...
...

    # HERE IS THE CAUSE #
    if ext not in s.get("file_types"):
      return False
    
    # ALSO TRIED THIS, DIDN"T WORK #
    if ext not in s.get("file_types",  'php', 'html', 'htm']):
      return false

    # THIS WORKAROUND FIXED THE LOADING ISSUE, HOWEVER NOW THE USER CAN'T SET FILETYPES #
    if ext not in 'php', 'html', 'htm']:
      return False

   #
   # What finally worked was "reinitializing" the settings variable using the 
   # global keyword in my run function, kinda lame as i had already done this elsewhere 
   # and it means the settings get checked every single time the command is run.
   #

   # FINAL PRODUCTION FIX #
   def run(self, edit, shadow_copy=False, process_directory=False):
     global s
     s = sublime.load_settings("PhpBeautify.sublime-settings")
0 Likes

#5

as I said continue here Plugin not activating

DO YOU REALLY NEED TWO THREADS FOR THE SAME THING

0 Likes