Hi everyone. I made a simple autocomplete plugin using someone else’s template. It works fine on my Windows 10 machine but on Mac it only works after I open the .py
file, hit Save
to see a reloading plugin User.case_completions
message. Could you please help me: why is this happening?
The plugin:
import sublime
import sublime_plugin
class CaseCompletionsListener(sublime_plugin.EventListener):
items = []
def __init__(self, *args, **kwargs):
self.settings = sublime.load_settings('cases_dictionary.sublime-settings')
self.items = self.settings.get('items')
def on_query_completions(self, view, prefix, locations):
self.completions = []
if not view.match_selector(locations[0], 'plain.strings'):
return []
default_completions = [view.extract_completions(prefix)]
default_completions = [(item, item) for sublist in default_completions for item in sublist if len(item) > 3]
default_completions = list(set(default_completions))
completions = list(self.items)
completions = [tuple(attr) for attr in self.items]
completions.extend(default_completions)
return (completions)
Sample content of the cases_dictionary.sublime-settings
:
{
"items": [
["pinkpowder\tlab_402", "402"],
["water\tlab_430", "430"],
["securitycamera\tlab_405", "405"],
["whitepowder\tele_514", "514"],
["result_whitepowder\tele_515", "515"],
["restoredphoto\tele_516", "516"],
["result_sandwich\tele_506", "506"],
["sandwich\tele_507", "507"],
["result_momsnote\tele_508", "508"],
["restoredcardboard\tele_509", "509"],
["result_ironchains\tele_519", "519"],
]
}
If I don’t force save it, here’s the message I’m getting:
Traceback (most recent call last):
File "/Applications/Sublime [Text.app/Contents/MacOS/sublime_plugin.py](http://text.app/Contents/MacOS/sublime_plugin.py)", line 688, in on_query_completions
res = callback.on_query_completions(v, prefix, locations)
File "/Users/zahra/Library/Application Support/Sublime Text 3/Packages/User/case_completions.py", line 22, in on_query_completions
completions = list(self.items)
TypeError: 'NoneType' object is not iterable
It’s like it didn’t read the .sublime-settings
file?